想做一个类似半透明效果的小例子,没头绪,仅仅是透明图片,不要什么窗口透明然后再画窗口背景的,
没有一点意义,就是一张png图片,加入叫做IDB_PNG1或者Image* pImg,让它半透明,类似SolidBrush br(Color(100, 255, 0, 0));
graphics.FillRectangle(&br, rcClient);
请问如何做到?希望高人指点一下。

解决方案 »

  1.   

    png支持半透明的吧。不用你可以去实现
      

  2.   

    Graphics graphics(pDC->GetSafeHdc()); //CDC *pDC
    Image image(L"bk.png");
    graphics.DrawImage(&image, 0, 0);
      

  3.   

    本帖最后由 xianglitian 于 2010-12-01 14:59:40 编辑
      

  4.   

    http://blog.csdn.net/maozefa/archive/2007/12/27/1995949.aspx它这里讲的很详细,最下面的图,就是半透明的.
      

  5.   


    您或许是个高手,可您看看您的回答:PNG支持半透明。就比如我问您是哪里人,您回答地球人一样!
    如果我有不礼貌我跟您道歉,我只是来问个问题,我只想有人懂得的可以赐教下,技术本来就是交流出来的,可您的回答觉得对得起您两颗星吗?
      

  6.   

    现在提问的人都好吊,好多大牛都怕了。半透明:本身就是个很模糊的词。
    1.可以理解为图片有一部分颜色被定义为透明
    2.还有本身图片都是有透明效果的颜色填充别人理解错了很正常,别人花费时间来回答你就很不错了,CSDN本来就不给钱的。
      

  7.   


    +1 ,楼主正巧问到一个支持alpha的图片格式如何透明绘制,正常的想法应该都是直接绘制了。
      

  8.   

    Bitmap bitmap(L"Texture1.jpg");
    Pen pen(Color(255, 0, 0, 0), 25);
    // Initialize the color matrix.
    // Notice the value 0.8 in row 4, column 4.
    ColorMatrix colorMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                               0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
                               0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                               0.0f, 0.0f, 0.0f, 0.8f, 0.0f,
                               0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
    // Create an ImageAttributes object and set its color matrix.
    ImageAttributes imageAtt;
    imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault,
       ColorAdjustTypeBitmap);
    // First draw a wide black line.
    graphics.DrawLine(&pen, Point(10, 35), Point(200, 35));
    // Now draw the semitransparent bitmap image.
    INT iWidth = bitmap.GetWidth();
    INT iHeight = bitmap.GetHeight();
    graphics.DrawImage(
       &bitmap, 
       Rect(30, 0, iWidth, iHeight),  // Destination rectangle
       0,                             // Source rectangle X 
       0,                             // Source rectangle Y
       iWidth,                        // Source rectangle width
       iHeight,                       // Source rectangle height
       UnitPixel, 
       &imageAtt);