Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i 'm trying to Dissolve 2 image with a pixel format of 24bit.This is my code:
public static Bitmap ghepanh_normal(Bitmap anhnguon, Bitmap mask,Bitmap ketqua, double alpha)
       {
           Rectangle rec1 = new Rectangle(0, 0, anhnguon.Width, anhnguon.Height);
           Rectangle rec2 = new Rectangle(0, 0, mask.Width, mask.Height);
           //Bitmap ketqua = new Bitmap(soure.Width, soure.Height);
           ketqua = new Bitmap(soure);
           int cao = soure.Height;
           int ngang = soure.Width;


              // ketqua.Height = cao;
               //ketqua.Width = ngang;
               //ketqua = null;
           xuli.xamhoa(mask);

               Rectangle rec3 = new Rectangle(0, 0, ketqua.Width, ketqua.Height);
               BitmapData bmdata_nguon = anhnguon.LockBits(rec1, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
               BitmapData bmdata_mask = mask.LockBits(rec2, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
               BitmapData bmdata_ketqua = ketqua.LockBits(rec3, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
               int stride1 = bmdata_nguon.Stride;
               int offset1 = stride1 - anhnguon.Width * 3;
               int stride2 = bmdata_mask.Stride;
               int offset2 = stride2 - mask.Width * 3;
               int stride3 = bmdata_ketqua.Stride;
               int offset3 = stride3 - ketqua.Width * 3;
               IntPtr ptr1 = bmdata_nguon.Scan0;
               IntPtr ptr2 = bmdata_mask.Scan0;
               IntPtr ptr3 = bmdata_ketqua.Scan0;

               unsafe
               {
                   byte* p1 = (byte*)ptr1;
                   byte* p2 = (byte*)ptr2;
                   byte* p3 = (byte*)ptr3;
                   for (int y = 0; y < anhnguon.Height; y++)
                   {
                       for (int x = 0; x < anhnguon.Width * 3; x++)
                       {
                           p3[0] = (byte)(p1[0] * (1 - alpha) + p2[0] * alpha);
                           p1++;
                           p2++;
                           p3++;
                       }
                       p1 += offset1;
                       p2 += offset2;
                       p3 += offset3;
                   }
               }
               anhnguon.UnlockBits(bmdata_nguon);
               mask.UnlockBits(bmdata_mask);
               ketqua.UnlockBits(bmdata_ketqua);
               return (ketqua);



       }

But i not satisfy with my result!
i set 0< alpha <1 but the result :-??
alpha =1: result ketqua = texture
alpha !=1: ketqua = soure

i want to change the opacity of the image texture!! Can you help me??

EDIT ==================

i put the image in a picturebox but i didn't know how to set the opacity because i couldn't set the opacity of an image with a pixel format of 24 bpp

EDIT ==================

i think i will convert the image format to 32bpp then set the opacity of new image and last convert the new image format to 24bpp!!

can i do it??
Posted
Updated 28-Sep-10 9:34am
v3

If you would just use google (I searched for "C# image opacity"), you'd have your answer:

http://www.geekpedia.com/code110_Set-Image-Opacity-Using-Csharp.html[^]

Not only does it provide a complete method for setting image opacity, but it was the very first result returned in google.

And for whatever good it's going to do me to mention this, voting someone's attempt to help you with a 1 is NOT the best way I know of to get further help here.
 
Share this answer
 
v2
before i have a question for you i had read the site which you gave me but i can't do as that code!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900