473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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<graphics.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 4102

"jt" <ka**********@gmail.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<graphics.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<graphics.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<graphics.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....@gmail.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<graphics.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*******@btinternet.comwrote in message
news:w8******************************@bt.com...
>
"jt" <ka**********@gmail.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<graphics.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.
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.comwrote in message
news:ff**********************************@34g2000h sf.googlegroups.com...
On May 10, 8:55 am, jt <karthiks....@gmail.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
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...
12
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...
2
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...
14
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...
5
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...
6
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...
12
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...
6
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...
9
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()...
8
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.