954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# Gradient over bitmap

Hi all.

Could anyone give me a pointer please?

I've almost finished a project I'm working on but have one last issue to resolve.
I have an image on a form that I apply a colour gradient to. However, when I grab this to create a bitmap (this.DrawToBitmap(BackGroundBmp, BackGroundRect);) I do not get the gradient. So, I've applied the gradient to the bitmap directly. However this is noticeably darker than the form image with the gradient over it. Any idea?

Bitmap BackGroundBmp = new Bitmap(this.Width, this.Height);
Rectangle BackGroundRect = new Rectangle(0, 0,this.Width, this.Height);
this.DrawToBitmap(BackGroundBmp, BackGroundRect);


Graphics g = Graphics.FromImage(BackGroundBmp);
g.FillRectangle(RenderBGGradient, RenderBGGradBrush);


Thanks in advance.

PyroPaul2
Newbie Poster
10 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

I'm not going to pretend that I understand why but even though the image on the form had a gradient on it, but was not visible in the bitmap that was rendered (using -> this.DrawToBitmap), it must have some how applied this gradient (I'm using alpha blend in the gradient). It was doubling up on the gradient that was applied to the form and the bitmap...... which made it darker. I applied the gradient straight to the bitmap......problem solved. The gradient wasn't visible in the rendered bitmap so, therefore, if I'd not been so sloppy and removed the code that applied the gradient to the form, I would have solved this sooner.

PyroPaul2
Newbie Poster
10 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

That's great you got it solved. Why not post the finished code (using CODE TAGS) so that when others are searching for an answer to their problem they can find and benefit from your solution?

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: