如何在VC ++中将png图像转换为字节数组? [英] how to convert png image into byte array in VC++?

查看:242
本文介绍了如何在VC ++中将png图像转换为字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用ATLImage库加载一个png图像。



Hi,
I m loading a png image by using the ATLImage library.

CImage Image;
Image.Load (L"D:\\Images\\PNG_Images\\Image7.png");



如何检索此png图像的字节数组值。



我尝试将其检索为




how to retrieve the byte array value of this png image.

I tried retrieving it as

byte *png = reinterpret_cast<byte>(Image.GetBits());



但是当我访问数据时,der是以上述方式转换数据时丢失的数据。



我在网上找到了一个解码原始数据的片段。但是der是一行是我不知道的代码。

代码如下:




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;
}



如何从加载的png图像中获取字节*值?



谢谢你提前回复:)

问候,

Sandhya。


How do I get the byte * value form the png image loaded?

Thankx a ton in advance for reply :)
Regards,
Sandhya .

推荐答案

而iImageSize.x是未知的,它可以获得图像大小:

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



还可以考虑使用static_cast更改reinterpret_cast



我希望它能帮助


Also consider to change reinterpret_cast with static_cast

I hope it will help


为什么不检查 CImage :: GetWidth [ ^ ]函数给出正确的值?
Why not check if the CImage::GetWidth[^] function gives the right value?


我试过这样做,但问题是获得的值给出宽度而不是x,太大了,代码崩溃给垃圾价值。



无论是否考虑reinterpret_cast或static_cast都没有差异....
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....


这篇关于如何在VC ++中将png图像转换为字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆