-
March 12th, 2013, 12:54 AM
#1
how to convert png image into byte array in VC++??
Hi,
I m loading a png image by using the ATLImage library.
CImage Image;
Image.Load (L"D:\\Images\\PNG_Images\\Image7.png");
how to retrieve the byte array value of this png image.
I tried retrieving it as
byte *png = reinterpret_cast<BYTE *>(Image.GetBits());
but when i access the data , der is a loss of data while converting it in the above manner.
I found a snippet in net for decoding the raw data . but der is a line is the code which is unknown to me.
The code is as follows :
CImage atlImage;
HMODULE hMod = GetModuleHandle(NULL);
atlImage.Load(bstr);
void* pPixel = atlImage.GetBits();
int pitch = atlImage.GetPitch();
int depth = atlImage.GetBPP();
INT32 bytes = (iImageSize.x * depth) / 8;// iImageSize.x is unknown
const BYTE* src = (const BYTE*)pPixel;
BYTE* dst = (BYTE*) pBitmapData; //valid memory buffer
for (int jj = atlImage.GetHeight(); --jj >= 0; )
{
memcpy(dst, src, bytes);
src += pitch;
dst += pitch;
}
How do I get the byte * value form the png image loaded?
Thankx a ton in advance for reply
Regards,
Sandhya .
-
March 12th, 2013, 08:03 AM
#2
Re: how to convert png image into byte array in VC++??
if you want the pixel values so you can change the image.
Then make a memory bitmap (Dib section), paint/blit the image into that, then you can access the individual pixel values. Make sure you create the dib section with the desired memory layout.
The ATL lib is a wrapper on GDI+. GDI+ doesn't provide you with access to individual pixels directly, in fact, there isn't even a guarantee the bitmap is entirely loaded in memory at any point in time. (you will notice that when opening a bitmap from file that the file remains open and locked for this reason). This is why you need to paint it to an actual memory bitmap first. If you need to get it back into a CImage, there's functions to convert/load a dib-section into a CImage. The process of copying into the memory bitmap and back are "slow" though. If you want to achieve animation with this, this isn't going to work very well.
-
March 12th, 2013, 08:10 AM
#3
Re: how to convert png image into byte array in VC++??
if you want the pixel values so you can change the image.
Then make a memory bitmap (Dib section), paint/blit the image into that, then you can access the individual pixel values. Make sure you create the dib section with the desired memory layout.
The ATL lib is a wrapper on GDI+. GDI+ doesn't provide you with access to individual pixels directly, in fact, there isn't even a guarantee the bitmap is entirely loaded in memory at any point in time. (you will notice that when opening a bitmap from file that the file remains open and locked for this reason). This is why you need to paint it to an actual memory bitmap first. If you need to get it back into a CImage, there's functions to convert/load a dib-section into a CImage. The process of copying into the memory bitmap and back are "slow" though. If you want to achieve animation with this, this isn't going to work very well.
-
March 13th, 2013, 01:01 AM
#4
Re: how to convert png image into byte array in VC++??
that really went above my head.. Can you pls temme me in simple context of how i can retrieve the byte array from png image..
Tags for this Thread
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
|