draw a bitmap over another bitmap

alexying

Member
Joined
May 26, 2003
Messages
9
hi,

I want to draw Bitmap A over Bitmap B. Bitmap A has string A on it and Bitmap B has red color rectangle on it. when i draw Bitmap A over Bitmap B, i will see string A on a red color rectangle. Now, when i brush Bitmap B with greed color. then draw Bitmap A over Bitmap B, i will see string A on a green color rectangle.

My question is:

when i try to change string A to string B on Bitmap A, i dont know how to do it. In a normal way, i will brush Bitmap A with some background color , then draw a new string B on it. But i dont know what background color that Bitmap A has because when i create Bitmap A, i did not specify any background color for it.

if i brush Bitmap A with any color and draw string B on it, then when i draw Bitmap A over Bitmap B, i will not see the color rectangle of Bitmap B.

I have tried to use BitmapA.GetPixel() to get the background color of Bitmap A and brush Bitmap A with this color, then draw string B on Bitmap A. But, it didnt work, i saw both string A and string B over each other.

Can anyone help me out?

thanks
 
Why didnt GetPixel work in getting the color of the Bitmap? How did you use it? Some code please. Also post code about how you are brushing over the text, filling the Bitmap with a solid color.
 
thanks for asking.

here is the some code:


Bitmap bitmapB = new Bitmap(300,300);
Graphics gB = Graphics.FromImage(bitmapB);
gB.FillRectangle(Brushes.Red,0,0,100,100);
gB.Dispose();

Bitmap bitmapA = new Bitmap(300,300);
Color backColor = bitmapA.GetPixel(1,1);
Graphics gA = Graphics.FromImage(bitmapA);
gA.DrawString("AAAAAA",Font, Brushes.Black,0,0);
gA.FillRectangle(new SolidBrush(backColor),0,0,100,100);
gA.DrawString("BBBBBB",Font,Brushes.Black,0,0):
gA.Dispose();


protected override void OnPaint(PaintEventArgs e){
e.Graphics.DrawImageUnscaled(bitmapA,0,0);
e.Graphics.DrawImageUnscaled(bitmapB,0,0);
}
 
sorry, the last two lines are reversed:

protected override void OnPaint(PaintEventArgs e){
e.Graphics.DrawImageUnscaled(bitmapB,0,0);
e.Graphics.DrawImageUnscaled(bitmapA,0,0);
}
 
Does this even compile?
gA.DrawString("AAAAAA",Font, Brushes.Black,0,0);
Font can present a problem, there is a Font class in the framework.

The background of the Bitmap is Black (I beleive) when you create a new Bitmap. On BitmapA you are drawing the text black too...
 
Back
Top