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 .[code="cpp"]


  • Mod

    This is a German Forum.

    What Kind of "Byte Array" do you want? Just the PNG Stream. Than read it from disk?


Anmelden zum Antworten