更改图片格式 [英] change the picture format

查看:118
本文介绍了更改图片格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一个位图.但是位图太大.我希望它很小.所以我将位图格式从bmp更改为gif.然后我将此gif作为源添加到我的项目中.当我的程序正在运行时,我想将图片格式从gif更改为bmp agan.i编写类似tihs的函数:


布尔CLoadDlg :: GIFToBMP(CString& strGIFFile,CString& strBMPFile)
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(& gdiplusToken,& gdiplusStartupInput,NULL);

CLSID编码器
GetEncoderClsid(L"image/bmp",& encoderClsid); //i从GDI + SDK复制"GetEncoderClsid"函数.
//图像image(strGIFFile.AllocSysString());
HRSRC hrsc = FindResource(NULL,MAKEINTRESOURCE(IDR_GIF1),"GIF"); //"IDR_GIF1"是我的GIF的源ID.
HGLOBAL hG = LoadResource(NULL,hrsc);
//hG = LockResource(hG);
IStream * pStmImage = NULL;
CreateStreamOnHGlobal(hG,TRUE,& pStmImage);
图片图片(pStmImage);

状态stat = image.Save(strBMPFile.AllocSysString(),& encoderClsid,NULL);

GdiplusShutdown(gdiplusToken);
if(stat ==确定)
返回TRUE;
其他
返回FALSE;
}

但是当我调用此函数时,它没有任何作用...
请帮我,哪里错了.

my project have a bitmap.but the bitmap is too big.i want it small.so i change the bitmap format from bmp to gif.than i add this gif to my project as a source.when my program is runing,i want change the picture format from gif to bmp agan.i write a function like tihs:


BOOL CLoadDlg::GIFToBMP(CString& strGIFFile,CString& strBMPFile)
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

CLSID encoderClsid;
GetEncoderClsid(L"image/bmp", &encoderClsid); //i copy the "GetEncoderClsid"function from GDI+ SDK.
//Image image(strGIFFile.AllocSysString());
HRSRC hrsc = FindResource(NULL, MAKEINTRESOURCE(IDR_GIF1), "GIF"); //"IDR_GIF1"is my source-id of GIF .
HGLOBAL hG = LoadResource(NULL, hrsc);
//hG = LockResource(hG);
IStream* pStmImage = NULL;
CreateStreamOnHGlobal(hG, TRUE, &pStmImage);
Image image(pStmImage);

Status stat = image.Save(strBMPFile.AllocSysString(),&encoderClsid,NULL);

GdiplusShutdown(gdiplusToken);
if(stat == Ok)
return TRUE;
else
return FALSE;
}

but when i call this function,it have no effect...
please help me,where is wrong.

推荐答案

我不太了解-为什么您甚至需要这样做? bmp是未压缩的,但是gif,jpeg,bmp等在加载到内存中时都采用相同的格式.

您是什么意思没有作用"?图像不会保存吗?它不是位图吗?如果您有一个24位图像并将其保存为gif,则现在为8位,因此由于丢失的信息,保存到bmp会创建一个较小的bmp.
I don''t really understand - why do you even need to do this ? A bmp is uncompressed, but a gif, a jpeg, a bmp, etc, all take the same format when they have been loaded in memory.

What do you mean ''have no effect'' ? Does the image not get saved ? Is it not a bitmap ? If you had a 24 bit image and you saved it to gif, it''s now 8 bit, and so saving to bmp will create a smaller bmp, because of the information that was lost.


请编辑您的帖子,而不要发布确实是问题的答案.

您是否已逐步调试程序中的代码?是否创建了文件?您的资源是否正确加载?首先,将您当前的句柄替换为从光盘加载的同一个文件中保存的句柄.然后从那里向后工作.这样,您可以隔离出哪段代码失败.
Please edit your post instead of posting answers that are really questions.

Have you stepped through the code in your debugger ? Is a file created at all ? Is your resource loading properly ? I would start by replacing your current handle to save with one you load from disc, of the same file. Then work backwards from there. That way you can isolate which piece of code is failing.


这篇关于更改图片格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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