如何在不使用alphablend的情况下设置透明像素 [英] How to set transparent pixel without using alphablend

查看:83
本文介绍了如何在不使用alphablend的情况下设置透明像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的目的是在OnInitDialog上一次加载Image并在该Image上设置几种透明像素颜色.在我当前的代码中,像素颜色填充在Image上,我完全看不到基于Image的图像.这是我的代码.

BOOL CTestColorDlg :: OnInitDialog()
{

Hi,

My purpose is to load Image one time at OnInitDialog and set several transparent pixel color on that Image. In my current code, pixel color are filled over Image and I totally can''t see the based Image. Here is my code.

BOOL CTestColorDlg::OnInitDialog()
{

CString szFileName(_T("C:\\Users\\User\\Desktop\\ImageData.bmp"));
    hBmp = (HBITMAP)::LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0,  LR_LOADFROMFILE);
    m_bitmap.SetBitmap(hBmp); //hBmp is HBITMAP type member variable
    return TRUE;


}

void CTestColorDlg :: OnPaint()
{


}

void CTestColorDlg::OnPaint()
{

CDialogEx::OnPaint();
ShowPixelData();


}

void CTestColorDlg :: ShowPixelData()
{


}

void CTestColorDlg::ShowPixelData()
{

BITMAP bmpInfo;
   GetObject(hBmp, sizeof(BITMAP), &bmpInfo);

   CDC* pdc = GetDC();
   CDC memDC;
   if (memDC.CreateCompatibleDC(pdc))
   {
		HBITMAP old_hBitmap = (HBITMAP)memDC.SelectObject(hBmp);
		memDC.SetBkColor(TRANSPARENT);

		for (int i = 0; i < bmpInfo.bmHeight; i++) {
			for(int j = 0; j < bmpInfo.bmWidth; j++) {
				memDC.SetPixel(j, i, RGB(200, 100, 0)); 
			}
    }

	//pdc->BitBlt(100, 100, bmpInfo.bmWidth+100, bmpInfo.bmHeight+100, &memDC, 0, 0,  SRCAND);
	memDC.SelectObject((HBITMAP)old_hBitmap);
	memDC.DeleteDC();
   }

   ReleaseDC(pdc);


}

我想查看图像并在其上填充透明颜色.使用上面的代码,我只能在图像上看到不透明的颜色.有人可以给我一些建议,建议您根据上层代码显示透明颜色吗? (我不想使用alphablend.)

当我想设置完全不同的setpixel颜色时,清除setpixel颜色的最佳方法是什么?我应该重新绘制图像并再次设置不同的颜色吗?

在高级中表示感谢.


}

I want to see the Image and fill transparent color on it. With the upper code, I just can see opaque color fill on the Image. Could anyone give me advice for showing transparent color based on upper code? (I don''t want to use alphablend.)

And what is the best way to clear setpixel color, when I would like to set completely different setpixel color ? Should I redraw Image and set different color again ??

Thanks in advanced.

推荐答案

使用
Use GDI+[^], something like this should work:
#include <gdiplus.h>
...
  Gdiplus::Graphics g(memDC);
  g.SetPageUnit(Gdiplus::UnitPixel);

  Gdiplus::SolidBrush brush(Gdiplus::Color(128, 200, 100, 0));
  for (int i = 0; i < bmpInfo.bmHeight; i++) {
    for(int j = 0; j < bmpInfo.bmWidth; j++) {
      g.FillRectangle(&brush, j, i, 1, 1);
    }
  }
...



您还需要使用
GdiplusStartup [ ^ ]和 GdiplusShutDown [ ^ ].

有关详细信息,请参见有关GDI +的MSDN.



You also need to initialize and shut down GDI+ somewhere in your code using GdiplusStartup[^] and GdiplusShutDown[^].

See MSDN about GDI+ for details...


这篇关于如何在不使用alphablend的情况下设置透明像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆