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