-
August 13th, 2009, 03:34 AM
#1
creating an image from CImage
Greetings All,
simple question, I have raw image data ( unsigned char* ), image height and width, and all the relevant info for the image and I need to use CImage to save a Jpg file...
Saving the image is fine, but what I can't figure out is how to create a CImage and give it the raw image data, if this can be done with as little microsoftisms as possible that would be nice ( although I figure this isn't the case! )...
Any help on this matter would be appreciated....
Code:
unsigned char* ptr; // this has image data
unsigned int width;
unsigned int height;
CImage image;
// what goes here???
// or more specifically, how can I use the above vars in this CImage....
image.Save( "myImage.jpg", Gdiplus::ImageFormatJPEG );
Many thanks.
-
August 13th, 2009, 08:08 AM
#2
Re: creating an image from CImage
Use CImage::Create() to set the height, width, and BPP, then use CImage::GetBits() to get a pointer to the actual bits. Use this pointer as a destination and copy your bit data to the destination. One caveat: the actual pixel buffer is a "bottom-up" buffer so GetBits() will return a pointer near the end of the pixel buffer. You fill the buffer "backwards" so to speak. See:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclib/html/48e842f6-cffa-4e61-8259-e8255a31739c.htm
or
http://msdn.microsoft.com/en-us/library/zx1ex9b5.aspx
-
August 13th, 2009, 09:13 AM
#3
Re: creating an image from CImage
Ok, many thanks hoxsiew for your reply....
It all makes sense theoretically, however, you can probably guess what my problem is... getting a black image. Am I doing this right? I'm not to bothered at the mo about orientation.
Code:
unsigned char* ptr; // this has image data
unsigned int width;
unsigned int height;
CImage image;
image.Create( width, height, 32 );
unsigned char* imagePtr = static_cast< unsigned char* >( image.GetBits() );
imagePtr -= ( width * height );
*imagePtr = *ptr;
image.Save( "myImage.jpg", Gdiplus::ImageFormatJPEG );
Many thanks for your help...
Last edited by lemonsF; August 13th, 2009 at 09:15 AM.
-
August 13th, 2009, 09:22 AM
#4
Re: creating an image from CImage
Oooops... school boy error...
Code:
for ( unsigned int i = 0 ; i < ( width * height ); ++i )
{
*imagePtr = *ptr;
--imagePtr;
++ptr;
}
Getting closer.......i'll be there in a bit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|