JPEG compressing without DLLs
I want to convert raw RGB image data (I could add BMP header if necessary) to 开发者_JS百科JPEG on Windows. Is it possible to do so without DLLs? I tried statically compiling IJG jpeglib, but I have VC++ 9, and it only works for VC++ 10
Use GDI+ to save the image to a file. For example, see http://msdn.microsoft.com/en-us/library/ms535407(VS.85).aspx for how to save to a file. Specify the JPEG encoder. To load the image into the Image class, you can use the Bitmap class (inherits from Image). Several methods are available: http://msdn.microsoft.com/en-us/library/ms536286(VS.85).aspx.
GDI+ comes with Windows XP and newer and can be redistributed for older Windows versions. So you probably won't need to bundle anything newer.
Yes, either write your own JPEG encoder or use other lib, like OpenCV. Just take care of its licensing requirements when you static link them
The reference implementation is freely available and usable for any kind of project.
Also, you can write JPEG images using GDI+ (without any extra libraries that Windows doesn't already have anyway).
For that, create a Bitmap
, LockBits
to get a writable pointer, write the data, and UnlockBits
.
If the image was captured from OpenGL, you must RotateFlip
it, or it will be upside down.
Now create a PropertyItem
and fill in the metadata, then SetPropertyItem
on your Bitmap
.
Create and initialize an EncoderParameters
, here you set the quality and whatnot.
Lastly, call Save
on your Bitmap
.
精彩评论