|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
IJG: Jpeg to HBITMAP or JPeg use in general
Hello. First of all, I have been making use of the excellent tutorials here for some time.. but Im new to this forum. I read the rules thread and did a search on this topic.. so I apologize if I'm missing something obvious.
I am new to the winAPI.. I am working entirely in C.. and have been doing custom shaped windows and skinning them with bmp's for this project I am doing. But I would really like to reduce the size of the exe by using a jpeg resource instead of a bitmap. I've downloaded and compiled the IGJ library.. and there is code in there I could use.. but Im having difficulties getting the image data into an HBITMAP. I have searched google high and low and am having problems finding any built in library.. and most '3rd party' libraries involve 2D or 3D graphics manipulation.. licensing fee's, demo versions.. ect. I refuse to believe I am the first individual that has ever loaded a jpg into a windows program , and I feel retarded that I can't figure out how everyone is doing it.If someone could just point me in the right direction I would greatly appreciate it. Especially if I could stick with plain old C. We are trying to save every byte possible so we can email these programs to customers. Thanks in advance. |
|
#2
|
|||
|
|||
|
ok, you should understand some basics (and please correct me if i'm wrong):
- to load a bitmap to a reasource is as expensive as reading it from a file, or even more. (the size of the exe) - if you will load the bitmap from a file at run time you decrease the size of the exe but you will have to send the bmp file together with the exe. if you are not familiar with the API of reading from file i can explain. basically, to load an image from a file use LoadImage() (also relevant to pure C)
__________________
"Gravitation can NOT be responsible for people falling in Love" (one of the most significant characters in the history, can you guess?) Gmorph. |
|
#3
|
|||
|
|||
|
Yeah.. I can load the image from a file just fine. I included it in the exe file for ease of distribution. The difficulty I am having is using a jpg file.
|
|
#4
|
|||
|
|||
|
i think that if the Jpeg is valid it should work well with HBITMAP but refer to MSDN for deeper description.
try: BITMAP_FILE_HEADER BITMAP_INFO ... |
|
#5
|
|||
|
|||
|
starting with W2K, jpegs are natively supported by the GDI. i.e. you should be able to load them directly via LoadBitmap(), but i never tried...
For making my programs work with all Windozes, I always use intelīs(? - the one that comes with Borland C++ Builder) jpeg library. There you can load a jpeg from a file and draw() them to any HDC. (i.e. also to a Bitmap or DIB) i donīt have any code around as i am at home, but if you can ask a more specific question, iīll gladly try to help. M.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#6
|
|||
|
|||
|
UPDATE: I found my sources...
I just found the sources on a backup CD. I am using IJGīs library too.
using jpeg_read_scanlines(), you can decompress the jpeg line by line to a bitmapīs bitmap-data. the full process is quite complicated and many lines. And as i am using Delphi version and not C, i am not willing to translate all that right now. But i could post the relevant delphi code if you want... just tell me. |
|
#7
|
|||
|
|||
|
It looks like Intel isn't offering their jpg package anymore. Its now part of thier IPP package you have to purchase.
So IJG it is. If I'm going to work scanline to scanline, don't I need to invert the image? That is.. aren't bmp's stored from bottom to top? |
|
#8
|
|||
|
|||
|
I think the native support of JPEG images only works with a printer DC.
|
|
#9
|
|||
|
|||
|
3dfxMM: possible. as said, i never tested it since my software needs to work with older windozes too.
grunt: Quote:
so? how hard would it be to read the scanlines top to bottom and write bottom to top? But i canīt remember this strange behaviour on BMPs, could be that Delphi hides it from the user though... |
|
#10
|
|||
|
|||
|
Quote:
I wasn't commenting on difficulty.. but trying to clarify what would need to be done. I recall some of the IJG code reversing the scanlines for a bmp conversion.. and difficult or not, its somewhat important to get the pixel data correct. I think I can organize thier code well enough. If there aren't well known libraries or methods.. I guess my question becomes, how would one create/modify an HBITMAP with this data? |
|
#11
|
||||
|
||||
|
Quote:
of course it is ![]() Quote:
Just as you would do with any other bitmap too... Code:
pseudocode: ptr=CreateBitmap(width, height) bmpsize=width*height*bpp // bpp=bytes per pixel ptr+=sizeof(BITMAP_INFO)+bmpsize; for (i=0;i<height;i++) jpeg_read_scanlines(jc->d, ptr-i*width*bpp, 1); not syntax-checked nor logic-checked. probably needs several "+/-1" somewhere. probably all wrong and will blow up your whole PC. i take no responsibility for nothing ![]() Anyone got the time for making real code of this? |
|
#12
|
|||
|
|||
|
well.. I found an easier way than converting the image scanline by scanline:
PHP Code:
But now Im having issues loading the image from my resources instead of an external file. Im really not very good with the winAPI. Any ideas? |
|
#13
|
|||
|
|||
|
MS GDI+ will be very helpful to you.
It works with jpg, png, gif etc. It is free. download link: http://www.microsoft.com/downloads/...&DisplayLang=en |
|
#14
|
|
|
|