Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I m loading a png image by using the ATLImage library.

C++
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

C++
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 :

C++
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 .
Posted
Updated 11-Mar-13 23:39pm
v2

While iImageSize.x is unknown, it is posible to get image size:
C++
INT32 bytes = (atlImage.GetWidth() * depth) / 8;

Also consider to change reinterpret_cast with static_cast

I hope it will help
 
Share this answer
 
Why not check if the CImage::GetWidth[^] function gives the right value?
 
Share this answer
 
I tried doing this, But the issue is that the value obtained on giving width instead of the x, is too huge that the code crashes giving junk value.

No difference is found whether reinterpret_cast or static_cast is considered....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900