在圖片上 指定一個圓角矩形,將此部分區域做透明處理
1) 將黑色設置爲透明色的方式
原理:
圖片區域透明使用的原理是將圖片某矩形區域統一置黑色,再指定黑色爲透明色,繪製到目的圖片中,這樣在目的圖片中,矩形部分就成爲了透明區域
std::shared_ptr<Gdiplus::Bitmap> src_image_;
方法1:
MakeTransImg(int width, int height, std::wstring path)
{
image_list_.clear();
time_all_ = 0;
width += width % 2;
height += height % 2;
//創建位圖,最終在此位圖上 呈現區域透明的圖片
src_image_.reset(new Gdiplus::Bitmap(width, height, PixelFormat32bppARGB));
//創建臨時ARGB位圖 不能由圖片文件直接生成, 那樣可能不是ARGB格式
std::shared_ptr<Gdiplus::Bitmap> pTmpBitmap;
pTmpBitmap.reset(new Gdiplus::Bitmap(width, height, PixelFormat32bppARGB));
//創建原始圖像文件位圖
std::shared_ptr<Gdiplus::Bitmap> pOrgImg;
pOrgImg.reset(new Gdiplus::Bitmap(path.c_str()));
//將此圖像文件位圖繪製到臨時位圖中
Gdiplus::Graphics g(pTmpBitmap.get());
g.DrawImage(pOrgImg.get(), 0, 0, width, height);
//在臨時位圖中 將圓角矩形區域置