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);
ketqua = new Bitmap(soure);
int cao = soure.Height;
int ngang = soure.Width;
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??