VC6下怎样用GDI+实现对图像进行修改后保存?在自己写的图像处理软件中打开JPG,GIF,BMP图像,在图像上画矩形,然后点保存就将修改后的图像保存下来,怎样实现?
解决方案 »
- MDI中,在View类中如何获得MainFram中的public变量?
- 求MFC中组合框选项利用数据库中表项值动态赋值的方法
- 高手救命--------内存泄露
- 求教:扑克牌游戏外挂,的开发思路,请高手赐教!
- 用telnet命令 登陆FTP ,如何返回目录列表???
- 老问题了,寻求合适的API,请进
- 如何在网络中断时得到消息,类似Windows下托盘区的状态连通图标?
- 有没有什么工具能将一个动画截成一幅幅图片。
- 请问这个功能怎么实现?
- 用CString::Left()时,有时最后的汉字是一半,怎么办?
- 请问什么样的类需要去new?
- CFileDialog使用后,再去使用winExec就会失败,即:winExec调用的程序无法起来,不知是何原因?
Save需要结合CDC
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid); // helper functionINT main()
{
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); CLSID encoderClsid;
Status stat;
Image* image = new Image(L"Bird.bmp");
Graphics* g = new Graphics(image ); //Graphics::FromImage(&bmp);
SolidBrush br(Color(255, 255, 255));
g->FillRectangle(&br, RectF(0, 0, 100, 60)); delete g;
// Get the CLSID of the BMP encoder.
GetEncoderClsid(L"image/bmp", &encoderClsid); stat = image->Save(L"Bird.bmp", &encoderClsid, NULL); if(stat == Ok)
printf("Bird.png was saved successfully\n");
else
printf("Failure: stat = %d\n", stat); delete image;
GdiplusShutdown(gdiplusToken);
return 0;
}int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
} free(pImageCodecInfo);
return -1; // Failure
}
CLSID encoderClsid;
Status stat;
Image* image=new Image(L"4.jpg");
Graphics* g=new Graphics(image); //Graphics::FromImage(&bmp);
SolidBrush br(Color(255, 255, 255));
g->FillRectangle(&br, RectF(0, 0, 100, 60));
delete g;
// Get the CLSID of the BMP encoder.
GetEncoderClsid(L"image/bmp", &encoderClsid); stat = image->Save(L"4.jpg", &encoderClsid, NULL); if(stat == Ok)
AfxMessageBox("Bird.png was saved successfully\n");
else
AfxMessageBox("Failure: stat = %d\n"); delete image;
Image* image;
onopen()
{
image=new Image(L"4.jpg");
}OnDraw()
{
Graphics* g=new Graphics(image); //Graphics::FromImage(&bmp);
SolidBrush br(Color(255, 255, 255));
g->FillRectangle(&br, RectF(0, 0, 100, 60));
// 这里可添加将image绘制到界面的代码
...
delete g;
}
onsave()
{
CLSID encoderClsid;
GetEncoderClsid(L"image/jpg", &encoderClsid); image->Save(L"4.jpg", &encoderClsid, NULL);
}
例如www.OpenCV.org.cn
中国的程序员总是难以在巨人的肩膀上登高远望。