473,805 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

graphics in C to .jpg OR .bmp

jt
i think i was not clear in my quesiton.
my question actually was how to store a graphics image generated in C.

Eg.
#include<graphi cs.h>
void main()
{
int gm,gd=DETECT;
initgraph(&gd,& gm,"");
rectangle(50,50 ,200,300);
setcolor(1);
circle(150,150, 50);
save();
}

now save function should store the image generated into a jpeg file.
i think i was not clear in my last post.
sorry for the inconvinience.
actually i'm doing a project which is similar to paint in windows.
i wanted to give save option in my project.
thank you
with regards JT
Jun 27 '08 #1
6 4147

"jt" <ka**********@g mail.comwrote in message news:
>i think i was not clear in my quesiton.
my question actually was how to store a graphics image generated in C.

Eg.
#include<graphi cs.h>
void main()
{
int gm,gd=DETECT;
initgraph(&gd,& gm,"");
rectangle(50,50 ,200,300);
setcolor(1);
circle(150,150, 50);
save();
}

now save function should store the image generated into a jpeg file.
i think i was not clear in my last post.
sorry for the inconvinience.
actually i'm doing a project which is similar to paint in windows.
i wanted to give save option in my project.
Firstly you need to grab the drawing area as an array of rgb values. This
can be done by iteratively calling a function with a name like getpixel() or
similar - I am not familiar with your particular graphics package.

Once you've done that, grap my savejpeg.c program from my website and simply
call with the raster, the name of the file you wish to create, and the image
dimensions. You'll proably want to fiddle with the code to give control over
the compression ratio.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 27 '08 #2
jt wrote, On 10/05/08 08:55:
i think i was not clear in my quesiton.
my question actually was how to store a graphics image generated in C.

Eg.
#include<graphi cs.h>
This is a non-standard header, and apart from making the logical
assumption that it is for some kind of graphics library I have literally
no idea what it does.
void main()
void main() is not standard. You should use
int main(void)
{
int gm,gd=DETECT;
initgraph(&gd,& gm,"");
rectangle(50,50 ,200,300);
setcolor(1);
circle(150,150, 50);
Well, this presumable creates something in some format that the graphics
library you are using understands. However, none of the functions are
standard.
save();
}

now save function should store the image generated into a jpeg file.
People suggested some JPEG libraries, I suggest you look at them.
Someone also offered to email you some code.
i think i was not clear in my last post.
sorry for the inconvinience.
actually i'm doing a project which is similar to paint in windows.
i wanted to give save option in my project.
Nothing you have said here changes any of the earlier advice as far as I
can see.

Standard C does not provide for graphics or JPEG, so you need to either
roll your own or use a suitable third party library.
--
Flash Gordon
Jun 27 '08 #3
On 10 May 2008 at 7:55, jt wrote:
#include<graphi cs.h>
[snip]
save();

now save function should store the image generated into a jpeg file.
It seems extremely improbable that a save() function provided by a
graphics library a) would be called save() and b) would take no
arguments (path-name, overwrite?, format, format options, etc. probably
need to be supplied - not to mention a pointer to the image to be
saved!).

Checking the documentation for the library would be a good idea.

Jun 27 '08 #4
On May 10, 8:55*am, jt <karthiks....@g mail.comwrote:
i think i was not clear in my quesiton.
my question actually was how to store a graphics image generated in C.

Eg.
#include<graphi cs.h>
void main()
{
int gm,gd=DETECT;
initgraph(&gd,& gm,"");
rectangle(50,50 ,200,300);
setcolor(1);
circle(150,150, 50);
save();

}

now save function should store the image generated into a jpeg file.
i think i was not clear in my last post.
sorry for the inconvinience.
actually i'm doing a project which is similar to paint in windows.
i wanted to give save option in my project.
thank you
with regards JT
Perhaps jpeg is not the best choice. It's hellishly complicated, and
even if you use a library, doesn't work well with computer generated
images.

You mentioned BMP, which is reasonably straightforward , and there are
a few others.

First you need the image data is some memory-accessible format. And
you need to know exactly how the pixel data is arranged, before
converting to the file format.

Look for graphics or image file formats.

If you only need to reload the file into your own program, then it's
possible all you need to do is save the binary data directly to a
file, with some way of storing/deriving the image and pixel
dimensions.

--
Bartc
Jun 27 '08 #5

"Malcolm McLean" <re*******@btin ternet.comwrote in message
news:w8******** *************** *******@bt.com. ..
>
"jt" <ka**********@g mail.comwrote in message news:
>>i think i was not clear in my quesiton.
my question actually was how to store a graphics image generated in C.

Eg.
#include<graph ics.h>
void main()
{
int gm,gd=DETECT;
initgraph(&gd, &gm,"");
rectangle(50,5 0,200,300);
setcolor(1);
circle(150,150 ,50);
save();
}

now save function should store the image generated into a jpeg file.
i think i was not clear in my last post.
sorry for the inconvinience.
actually i'm doing a project which is similar to paint in windows.
i wanted to give save option in my project.
Firstly you need to grab the drawing area as an array of rgb values. This
can be done by iteratively calling a function with a name like getpixel()
or similar - I am not familiar with your particular graphics package.
I think I recognize it...

I think it is some Borland specific graphics interface (I think I remember
it being available with their older DOS-based compilers, don't know if it is
still maintained, or has been cloned...).
my opinion:
this is not likely the way I would do graphics;
usually, if I am doing any kind of raster graphics, I usually use a big flat
array which I can draw into directly;
as needed, this framebuffer can be drawn in whatever way is useful, or can
be saved to a file or whatever (explicit framebuffers are far more general
and flexible than some special-purpose graphics library).

in my case, I usually use OpenGL, so glWritePixels is good for raw display,
or the image can be loaded into a texture (much more common IME), or
compressed and saved out (very often if I am drawing into images directly,
they are for some special task, such as serving as lightmaps, ... so, they
are usually created and stored out).

Once you've done that, grap my savejpeg.c program from my website and
simply call with the raster, the name of the file you wish to create, and
the image dimensions. You'll proably want to fiddle with the code to give
control over the compression ratio.
yeah.
in my case, I had used a floating point value for controlling the quality
level, and a special set of algos for analyzing the DCT blocks and comming
up with a good set of quantizer values (at the time, I beat them together
experimentally, and this worked acceptably).
for my higher-speed compressor, I think I had an algo that came up with
quantizers for a particular quality level, which was based on more or less a
hand-tuned set of exponential equations (linear, square, and cubic factors).

this was faster in that it did not involve scanning over the blocks, but had
a worse quality/ratio tradeoff as a reult of it being that the quantizers
were not really tuned to the image.

I think scaling a fixed table of quantizer values is also possible, but IME
does not really produce as good of results (the ideal relation between the
components at various quality levels does not seem to be strictly linear).
also possible would be to add a function to search for the best quality
setting to produce a given sized output (would be useful in allowing setting
particular bitrates for MJPEG files, ...).
or such...

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 27 '08 #6

"Bart" <bc@freeuk.comw rote in message
news:ff******** *************** ***********@34g 2000hsf.googleg roups.com...
On May 10, 8:55 am, jt <karthiks....@g mail.comwrote:
Perhaps jpeg is not the best choice. It's hellishly complicated, and
even if you use a library, doesn't work well with computer generated
images.
this is always a little of an ammusing misnomer IMO...

what jpeg does bad with, is not "computer generated images", per se, but
images with lots of harsh points or edges...

for example, if you have the output of scene rendered in a raytracer (or for
that matter, a game screenshot), usually these compress fairly effectively
with JPEG, despite their being "computer generated".
PNG is another format, which is technically, a lot simpler to implement than
JPEG, and still compresses fairly effectively. it is lossless, however, so
files will tend to be a little larger than JPEG (this depends heavily on the
particular image though, for example, PNG handles things like monochromatic
regions, harsh edges, and patterns very well).

libpng exists and may also be a reasonable option here.

You mentioned BMP, which is reasonably straightforward , and there are
a few others.
TGA is also fairly common, and is actually a simpler format than BMP.
both TGA and BMP are fairly simple formats though...

TGA can also optionally use RLE compression...

First you need the image data is some memory-accessible format. And
you need to know exactly how the pixel data is arranged, before
converting to the file format.

Look for graphics or image file formats.
seconded, BMP and TGA can be looked into as simple examples (code for
loading and saving them can also be beaten together fairly easily).

if one is dealing with 8 bit graphics, PCX may also be an option.

If you only need to reload the file into your own program, then it's
possible all you need to do is save the binary data directly to a
file, with some way of storing/deriving the image and pixel
dimensions.
could be a reasonable option, but if one is going to use any header, may as
well be something like a TGA header, at least so that the files can be
opened in existing apps...

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3383
by: JBiagio | last post by:
Hello All, I am attempting to learn a bit about the GDI+ transforms and charting data and I feel like I'm getting a handle on how the transforms work. My chart object has a large "canvas" bitmap that all data is scaled to and rendered on, and I display a smaller "window" of the canvas that the user can page through left and right. I've been able to scale my data (for the purposes of this discussion, x values are 0 - 2PI and y values...
12
2389
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
2
3604
by: John Bailo | last post by:
I am walking through some of the very first sample code from the book "Beginning .NET Game Programming" from Apress. I identify his sample code with //SC This code puzzles me: Graphics graph = new Graphics //SC // first of all there is no constructor for Graphics // so in the Form_Paint I use instead:
14
3105
by: Pmb | last post by:
At the moment I'm using Borland's C++ (http://www.borland.com/products/downloads/download_cbuilder.html#) I want to be able to take an array of points and plot them on the screen. Is there a way to do this? E.g. I want to be able to graph a function. At this point I'm not up to a level in C++ where I want to start learning Visual C++ so I don't want to go that route. Thanks
5
27169
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat) e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2, TheHeight1 + (390 + yPos))
6
3247
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
12
3606
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet utilities that allows you to view them with live rotation in a web browser. Also, it includes a introductory tutorial to POV-Ray.
6
1700
by: active | last post by:
I have an image and a graphics object created (FromImage) from that image. I need to create a new image and create a new graphics object from the new image. I want the new graphics object have all the properties of the old graphics object (like PageUnit and InterpolationMode...) Can I do that without setting them all one at a time?
9
2667
by: DaveL | last post by:
hello I have a Bit map 1367 wide 32 high this bitmap contains like 40 separate Images 32x32 I tell it the id*32 to get the approiate Image from the source Bitmap When i CreateGraphics() From the Standard CreateGraphics() function the code below works
8
3138
by: Abhiraj Chauhan | last post by:
I need someone to make an example of how to create a graphics window in VB.net 2008. I understand the basics of how to draw a rectangle and lines etc. What I need is an example of how to make a window that goes in a form that does the following: 1. When the application is run, the form has a graphics area within the form (not the entire form) colored white. 2. Two text boxes (not in the graphics area) for data entry used to define...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.