Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI+ SRCAND for Transparency?

GDI+ SRCAND for Transparency?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformsquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tagopi
    wrote on last edited by
    #1

    Hello Everybody, I am trying to do like this. loading a bitmap using Gdiplus and drawing that to a device context. Bitmap gbmp(bmpFile); Graphics g(dc.GetSafeHdc()); g.DrawImage(gbmp, x,y, Width, Height); this is drawing the bitmap fine. on the same device context, if i am trying to draw colors over the bitmap, then the colors are going backside of the bitmap and the bitmap is showing front. in mspaint, if i load an image, and draw colors, its spreading the colors over the bitmap. i want to do like that. is there anyway to do that? if i use BitBlt and SRCAND, then it is working fine, but i need in gdiplus. Thanks in advance, A. Gopinath.

    L 1 Reply Last reply
    0
    • T tagopi

      Hello Everybody, I am trying to do like this. loading a bitmap using Gdiplus and drawing that to a device context. Bitmap gbmp(bmpFile); Graphics g(dc.GetSafeHdc()); g.DrawImage(gbmp, x,y, Width, Height); this is drawing the bitmap fine. on the same device context, if i am trying to draw colors over the bitmap, then the colors are going backside of the bitmap and the bitmap is showing front. in mspaint, if i load an image, and draw colors, its spreading the colors over the bitmap. i want to do like that. is there anyway to do that? if i use BitBlt and SRCAND, then it is working fine, but i need in gdiplus. Thanks in advance, A. Gopinath.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi tagopi, I would suggest that you have a look at the SetColorMatrix function[^] which can be used for RGBA transformations. Here is an example from one of my personal projects:

      if(TRUE == m_bDisabled)
      {
      	Gdiplus::ImageAttributes imageAtt;
      	Gdiplus::ColorMatrix cm =
      	{
      		0.299f, 0.299f, 0.299F, 0, 0,
      		0.587f, 0.587f, 0.587f, 0, 0,
      		0.114F, 0.114F, 0.114F, 0, 0,
      		0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
      		0.0f, 0.0f, 0.0f, 0.0f, 1.0f
      	};
      	cm.m[3][3]+=0.01f;
      	imageAtt.SetColorMatrix(&cm, Gdiplus::ColorMatrixFlagsDefault,Gdiplus::ColorAdjustTypeBitmap);
      	gScreenBuffer.DrawImage(&memBitmap,Gdiplus::Rect(0, 0, memBitmap.GetWidth(), memBitmap.GetHeight()),0,0,memBitmap.GetWidth(),memBitmap.GetHeight(),Gdiplus::UnitPixel,&imageAtt);
      }
      

      This example is used to paint my bitmap in grayscale when a button is disabled. Good Luck, -David Delaune

      T 1 Reply Last reply
      0
      • L Lost User

        Hi tagopi, I would suggest that you have a look at the SetColorMatrix function[^] which can be used for RGBA transformations. Here is an example from one of my personal projects:

        if(TRUE == m_bDisabled)
        {
        	Gdiplus::ImageAttributes imageAtt;
        	Gdiplus::ColorMatrix cm =
        	{
        		0.299f, 0.299f, 0.299F, 0, 0,
        		0.587f, 0.587f, 0.587f, 0, 0,
        		0.114F, 0.114F, 0.114F, 0, 0,
        		0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
        		0.0f, 0.0f, 0.0f, 0.0f, 1.0f
        	};
        	cm.m[3][3]+=0.01f;
        	imageAtt.SetColorMatrix(&cm, Gdiplus::ColorMatrixFlagsDefault,Gdiplus::ColorAdjustTypeBitmap);
        	gScreenBuffer.DrawImage(&memBitmap,Gdiplus::Rect(0, 0, memBitmap.GetWidth(), memBitmap.GetHeight()),0,0,memBitmap.GetWidth(),memBitmap.GetHeight(),Gdiplus::UnitPixel,&imageAtt);
        }
        

        This example is used to paint my bitmap in grayscale when a button is disabled. Good Luck, -David Delaune

        T Offline
        T Offline
        tagopi
        wrote on last edited by
        #3

        Hello David, Thanks for your reply.. This works fine for me, i changed the values as needed by me. Thanks again. A. Gopinath.

        T 1 Reply Last reply
        0
        • T tagopi

          Hello David, Thanks for your reply.. This works fine for me, i changed the values as needed by me. Thanks again. A. Gopinath.

          T Offline
          T Offline
          tagopi
          wrote on last edited by
          #4

          Hello, Can i able to save this image in disk (with the transparency i changed). i tried to save using bitmap.save, it showing black image. Thanks, A. Gopinath.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups