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. Graphics
  4. How to make an image (bmp) transparent?

How to make an image (bmp) transparent?

Scheduled Pinned Locked Moved Graphics
questiontutorial
3 Posts 3 Posters 4 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.
  • B Offline
    B Offline
    bholoo
    wrote on last edited by
    #1

    Dear All Hi, I have a dialog on which there is an image. Now I want to place another smaller image on the previous image. This new image should be semi transparent i-e see through. I want to ask u people that how can I make this new smaller image (which I have placed on the previous image) semi transparent? So that the image beneath this new smaller image can be seen through it. Thanks in advance. Yasir

    M R 2 Replies Last reply
    0
    • B bholoo

      Dear All Hi, I have a dialog on which there is an image. Now I want to place another smaller image on the previous image. This new image should be semi transparent i-e see through. I want to ask u people that how can I make this new smaller image (which I have placed on the previous image) semi transparent? So that the image beneath this new smaller image can be seen through it. Thanks in advance. Yasir

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      One way is to use the GDI AlphaBlend() API to draw the semi-transparent image. Another way is to use GDI+. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • B bholoo

        Dear All Hi, I have a dialog on which there is an image. Now I want to place another smaller image on the previous image. This new image should be semi transparent i-e see through. I want to ask u people that how can I make this new smaller image (which I have placed on the previous image) semi transparent? So that the image beneath this new smaller image can be seen through it. Thanks in advance. Yasir

        R Offline
        R Offline
        Richard Blythe
        wrote on last edited by
        #3

        The GDI+ code that will make the image semi-transparent is to create a custom color matrix. This topic is too lengthy to get into specifics but here is some sample code the will get you started: //Define a color matrix that has 60% transparency //The value 0.6 in row 4, column 4 specifies the alpha float[][] matrixItems = { new float[] {1,0,0,0,0}, new float[] {0,1,0,0,0}, new float[] {0,0,1,0,0}, new float[] {0,0,0,0.6f,0}, new float[] {0,0,0,0,1}}; ColorMatrix colorMatrix = new ColorMatrix(matrixItems); //Now we need an ImageAttributes object ImageAtttributes imageAtt = new ImageAttributes(); imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, COlorAdjustType.Bitmap); //Here, we will now draw the image using the imageAtt //You will need to have a graphics object created. I am //using a graphics object with a var name of "g" g.DrawImage( myAlphaBitmap, //the image to be made semi-transparent new Rectangle(10,10,10,10), //destination bmp size 0.0f, //start drawing from the XPos 0.0f, //start drawing from the YPos myAlphaBitmap.Width, //draw all of the original width myAlphaBitmap.Height, //draw all of the original height GraphicsUnit.Pixel, //specify the graphics unit imageAtt); //use our custom imageAtt //release system resources imageAtt.Dispose(); //End of code---------------------------- Hopefully this will get you started in the right direction! Cheers! Richard may your code be error free

        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