CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    29

    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 .

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  4. #4
    Join Date
    Apr 2011
    Posts
    29

    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
  •  





Click Here to Expand Forum to Full Width

Featured