www.digitalmars.com         C & C++   DMDScript  

c++ - Working with JPEGs

reply Erik Weber <my_name_here mindspring.com> writes:
I am able to compile and pack bitmaps as resources into my
executables with rcc and dmc and then load them with LoadBitmap
and display them with standard GDI BitBlt. I am working with large
photographs and of course the equivalent JPEGs are as much as 10
times more compact. So I would like to learn how to do the same
things with an image format such as JPEG. Can anyone help me out
here?

1) How do I declare a JPEG image as a resource that Digital Mars
rcc (not MS rc) will compile?

2) How do I find and load the JPEG resource?

3) How do I translate the JPEG image data into a format that GDI
will render (such as a DIB into an offscreen DC)?

If this is complex and someone can provide a complete (C/C++)
example, I'm even willing to pay you a few bucks via money order
as a consulting fee.

Thanks,
Erik
Nov 16 2011
next sibling parent Bertel Brander <bertel post4.tele.dk> writes:
Den 16-11-2011 14:10, Erik Weber skrev:
 I am able to compile and pack bitmaps as resources into my
 executables with rcc and dmc and then load them with LoadBitmap
 and display them with standard GDI BitBlt. I am working with large
 photographs and of course the equivalent JPEGs are as much as 10
 times more compact. So I would like to learn how to do the same
 things with an image format such as JPEG. Can anyone help me out
 here?

 1) How do I declare a JPEG image as a resource that Digital Mars
 rcc (not MS rc) will compile?

 2) How do I find and load the JPEG resource?

 3) How do I translate the JPEG image data into a format that GDI
 will render (such as a DIB into an offscreen DC)?

You could check out jdraw here: http://damb.dk/graphics.php It can do the above, and a few things more Regards Bertel
Nov 16 2011
prev sibling parent reply "Nick Hofstetter" <nhofstetter gfg-group.com> writes:
I have not tried to do this just using Windows Functions. I have downloaded 
some freeware that converts the jpeg to a bitmap as my image requirements 
are complex, but if you just want to display a jpeg, you will need to do 
something like this:

Define the image to in the RC file as 'RCDATA'

image    RCDATA  "image.jpg"

You can then access the image using:

  HANDLE hResource;
  BYTE *lpText;
  int len;

    hResource = LoadResource(hInst, FindResource(hInst, "image", 
RT_RCDATA));
    lpText    = LockResource(hResource);
    len = SizeofResource(hInst, FindResource(hInst, "image", RT_RCDATA));

So lpText is pointing to the JPEG data and len is the length

To render it, you will need to convert it to a bitmap. So you will need to 
allocate some memory the size of the image plus the size of the 
BITMAPINFOHEADER.

In  the BITMAPINFOHEADER set the biCompression to BI_JPEG
Nov 16 2011
parent Erik Weber <my_name_here mindspring.com> writes:
Thank you both. Yeah I've been trying to keep it pure GDI, no MFC,
no GDI+ and so far so good. Now I've got lots more to chew on. I
will post again when I make some progress.

Thanks,
Erik
Nov 18 2011