如下函数
bool ChangeImageAlpha(const CString& imagePath, REAL alpha, const CString& savePath)
{
// Bitmap bitmap(L"imagePath");
Bitmap* bitmap=Bitmap::FromFile(L"imagePath");/* if (bitmap.GetLastStatus() != Ok)
return false;*/ int nWidth = bitmap->GetWidth();
int nHeight = bitmap->GetHeight(); // 构建新图像对象
Bitmap image(nWidth, nHeight);
Rect rect(0, 0, nWidth, nHeight); // 利用新图像对象绘制
Graphics graph(&image);
// CDC* pDC=GetDC();
// Graphics graph(pDC->GetSafeHdc()); // 构建颜色变换矩阵
ColorMatrix colorMatrix = {
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, alpha, 0,
0, 0, 0, 0, 1 }; ImageAttributes imageAttr; imageAttr.SetColorMatrix(&colorMatrix); // 运用颜色变换矩阵绘制新图像
graph.DrawImage(bitmap, rect, 0, 0, nWidth, nHeight, UnitPixel, &imageAttr);
CLSID encoderClsid; // 文件编码器的CLSID
CString strExt = savePath.Right(3); // 获得保存文件的扩展名
strExt.MakeLower(); // 根据扩展名获得不同的CLSID
if (strExt == L"png")
GetEncoderClsid(L"image/png", &encoderClsid);
else if (strExt == L"jpg")
GetEncoderClsid(L"image/jpeg", &encoderClsid);
else
GetEncoderClsid(L"image/bmp", &encoderClsid); if (image.Save(L"savePath", &encoderClsid, NULL) == Ok)
return true;
else
return false;
}
当ChangeImageAlpha(L"pic.jpg",0.5,L"pic.png");这样调用该函数时,编译没有错误,可为什么不能把值传给bitmap呢?
bool ChangeImageAlpha(const CString& imagePath, REAL alpha, const CString& savePath)
{
// Bitmap bitmap(L"imagePath");
Bitmap* bitmap=Bitmap::FromFile(L"imagePath");/* if (bitmap.GetLastStatus() != Ok)
return false;*/ int nWidth = bitmap->GetWidth();
int nHeight = bitmap->GetHeight(); // 构建新图像对象
Bitmap image(nWidth, nHeight);
Rect rect(0, 0, nWidth, nHeight); // 利用新图像对象绘制
Graphics graph(&image);
// CDC* pDC=GetDC();
// Graphics graph(pDC->GetSafeHdc()); // 构建颜色变换矩阵
ColorMatrix colorMatrix = {
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, alpha, 0,
0, 0, 0, 0, 1 }; ImageAttributes imageAttr; imageAttr.SetColorMatrix(&colorMatrix); // 运用颜色变换矩阵绘制新图像
graph.DrawImage(bitmap, rect, 0, 0, nWidth, nHeight, UnitPixel, &imageAttr);
CLSID encoderClsid; // 文件编码器的CLSID
CString strExt = savePath.Right(3); // 获得保存文件的扩展名
strExt.MakeLower(); // 根据扩展名获得不同的CLSID
if (strExt == L"png")
GetEncoderClsid(L"image/png", &encoderClsid);
else if (strExt == L"jpg")
GetEncoderClsid(L"image/jpeg", &encoderClsid);
else
GetEncoderClsid(L"image/bmp", &encoderClsid); if (image.Save(L"savePath", &encoderClsid, NULL) == Ok)
return true;
else
return false;
}
当ChangeImageAlpha(L"pic.jpg",0.5,L"pic.png");这样调用该函数时,编译没有错误,可为什么不能把值传给bitmap呢?
解决方案 »
- union mov 的问题
- 通用控件自绘问题
- 使用visual6.0编译MFC程序时候,出现....\debug\vc60.pdb'?怎么解决??????
- 新手提问
- 不用onOk,OnCancel,如何让DoModal()返回自己定义的一个int值?
- 怎样将汉字转换成区位码,VC中是否有着样的函数直接转换,如果没有的话,怎样做???????
- 任何实现编译器?
- 高手请进,C++算法极度挑战!!!本人已经一天没合眼了
- 如何用ado调用代参数的存储过程?
- 应该怎么办??(提供建议者也有分)
- 为什么INLINE没有展开呢?
- vc++中webbrowser控件如何根据Frame的名字获取IHTMLDocument3或IHTMLDocument2
Bitmap* bitmap=Bitmap::FromFile(imagePath);if (image.Save(savePath, &encoderClsid, NULL) == Ok)
bool ChangeImageAlpha(CString imagePath, REAL alpha, CString savePath)