Groups | Blog | Home
all groups > dotnet drawing api > march 2008 >

dotnet drawing api : Graphics.Drawimage . The pixels are blurred



Suresh Gladstone
3/17/2008 10:42:00 PM
Hi,
Iam Facing some problem in the gradient of pixels while invoking DrawIamge
of System.Graphics. My objective is to position a set of pixels in a bitmap
and enlarge it based on the dimension specified for the container.I choose
DrawImage method of Graphics object which Draws the specified portion of the
specified Image at the specified location and with the specified size.
While experimenting, I could see that the pixels drawn were enlarged and
stretched. But the rectangles of the pixels formed are blurred and forms a
gradient from the middle to the edges of each pixel rectangle. But what I
really want is something which is of equal gradient in the stretched pixel.
Please find the code snippet below,


private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Bitmap bg = new Bitmap(9, 8);// CREATING A BITMAP OBJECT WHICH SIZE
9X8, ADDING SIX PIXELS TO THE BITMAP
bg.SetPixel(1, 1, Color.Red);
bg.SetPixel(1, 3, Color.Blue);
bg.SetPixel(1, 5, Color.Green);
bg.SetPixel(3, 1, Color.Orange);
bg.SetPixel(3, 3, Color.Violet);
bg.SetPixel(3, 5, Color.Pink);
g.DrawImage(bg, 50, 50, 200, 200); //ENLARGING AND DRAWING THE
BITMAP TO SIZE 200 X 200
//HERE IS WHERE THE PIXELS FORM RECTANGLES WITH GRADIENT FROM MIDDLE
TO EDGES
}

My requirement is, the stretched pixel should be a rectangle with solid
color and constant gradient. How do I acheive this ?

Any help will be really appreciated.

Regards,
suresh


Michael C
3/19/2008 1:18:31 PM
"Suresh Gladstone" <SureshGladstone@discussions.microsoft.com> wrote in
message news:6A3DB223-E72E-45EE-9700-C8709E121313@microsoft.com...
[quoted text, click to view]

Play around with some of the properties of the graphics object, eg
e.Graphics.InterpolationMode and e.graphics.PixelOffsetMode. There's likely
some other properties that will affect the drawing also and some other's
that do not apply to drawing an image.

Michael

Bob Powell [MVP]
3/19/2008 10:31:29 PM
While you're doing what Michael said, go look at the #1 GDI+ question
which you will no-doubt be asking shortly.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
AddThis Social Bookmark Button