请问CImage保存PNG

tiaonewen 2012-12-18 09:13:06
请问CImage保存PNG怎么保存?我要那种带透明通道的,我测试下来都是白色和黑色。

什么原因?
...全文
218 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiaonewen 2012-12-21
  • 打赏
  • 举报
回复
2楼应该提醒我初始化GDI+,卡了半天了
tiaonewen 2012-12-21
  • 打赏
  • 举报
回复
已解决,多谢2楼的方法。
看不见的裂痕 2012-12-19
  • 打赏
  • 举报
回复
偶的导出实验代码。前面是图层导出,没用。后面是GDI+和CImage配合导出

void CXXXXXView::OnLayersExport()
{

	int iCount = m_ctrlMapX.GetLayers().GetCount();
	int i;
	for(i=2;i<=iCount;i++)
	{
		m_ctrlMapX.GetLayers().Item(i).SetVisible(FALSE);
	}

	double dWidth;
	double dHeight;
	CRect rect;
	m_ctrlMapX.GetClientRect(&rect);

	dWidth = rect.Width()/96;
	dHeight = rect.Height()/96;
	
	m_ctrlMapX.ExportMap(_T("C:\\abc.png"),miFormatPNG,dWidth,dHeight);  //默认路径1

	CImage tempCImage;
	tempCImage.Create(rect.Width(),rect.Height(),32);
	tempCImage.SetHasAlphaChannel(TRUE);
	tempCImage.Save(_T("C:\\abcd.png")); //保存路径1
	
	Image img(L"C:\\abcd.png");//保存路径1
	Image iSourceImage(L"C:\\abc.png");//默认路径1

	Graphics graphics(&img);
	graphics.SetSmoothingMode(SmoothingModeAntiAlias);
	graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);

	ImageAttributes imageAttr;
	imageAttr.SetColorKey(Gdiplus::Color(255,255,255),Gdiplus::Color(255,255,255),Gdiplus::ColorAdjustTypeDefault);//透明像素开始-结束
	graphics.DrawImage(&iSourceImage,Gdiplus::Rect(8,0,rect.Width(),rect.Height()),0,0,rect.Width(),rect.Height(),UnitPixel,&imageAttr);

	
	CLSID pngClsid;
	GetEncoderClsidOwn(L"image/png",&pngClsid);
	img.Save(L"C:\\1111.png",&pngClsid,NULL);
}
jimette 2012-12-19
  • 打赏
  • 举报
回复
我保存的bmp 也是黑白, 同求

19,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧