圖像處理---區域透明圖實現

 

在圖片上 指定一個圓角矩形,將此部分區域做透明處理

 

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);

	//在臨時位圖中 將圓角矩形區域置
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章