How can i fit an image to pictureBox1 sizeMode set to normal ? The image isnt in the center not like

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
And also in stretch mode it seems more resoltuion/quality then in normal.
In this screenshot the left pictureBox2 is set to stretch and the right pictureBox1 is set to normal.
I need it to be Normal in the sizeMode property but it seems that in normal the image lose quality and not fit to center of the pictureBox.

The left pictureBox2 size is: 456x468 and the right pictureBox1 size is also: 456x468
The image resolution on the hard disk is: 1280x720

Now if i delete pictureBox2 and make pictureBox1 wider bigger then the image seems to fit i think but the quality isnt smooth like it is in stretch mode.

In my code in runtime im using graphics and aa bu it dosent effect when its on normal mode.

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void DrawToImage()
{
<span style="color:Blue; if (pictureBox1.Image != <span style="color:Blue; null && _bmp != <span style="color:Blue; null && _points != <span style="color:Blue; null)
{
<span style="color:Blue; using (Graphics g = Graphics.FromImage(<span style="color:Blue; this.pictureBox1.Image))
{
<span style="color:Green; //draw the orig one backup image
g.Clear(Color.Transparent);
g.DrawImage(_bmp, 0, 0, _bmp.Width, _bmp.Height);

<span style="color:Green; //draw the shapes
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
<span style="color:Blue; using (SolidBrush myBrush = <span style="color:Blue; new SolidBrush(Color.Red))
{
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < _points.Count; i++)
{
<span style="color:Blue; try
{
Point pt = _points.Point;
g.FillEllipse(myBrush, <span style="color:Blue; new RectangleF(pt.X - _circleWidth / 2F, pt.Y - _circleWidth / 2F, _circleWidth, _circleWidth));
<span style="color:Blue; if (i > 0)
{
<span style="color:Blue; if (_points.Connected)
g.DrawLine(Pens.Blue, _points[i - 1].Point, _points.Point);
}
}
<span style="color:Blue; catch (Exception err)
{
<span style="color:Green; //...
}
}
}
}

<span style="color:Blue; this.pictureBox1.Refresh();
}
[/code]

I also have this render function but its not in use now an im not sure how to use it and what it suppose to do:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; void Render(Graphics g, <span style="color:Blue; float circleWidth)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
<span style="color:Blue; using (SolidBrush myBrush = <span style="color:Blue; new SolidBrush((<span style="color:Blue; this.IsCurrent) ? HotColor : ForeColor))
g.FillEllipse(myBrush, <span style="color:Blue; new RectangleF(Point.X - circleWidth / 2F, Point.Y - circleWidth / 2F, circleWidth, circleWidth));

<span style="color:Blue; if (<span style="color:Blue; this.Connected && Connection != <span style="color:Blue; null)
g.DrawLine(Pens.Blue, Connection.Point, Point);
}

<span style="color:Blue; public <span style="color:Blue; bool HitTest(<span style="color:Blue; float x, <span style="color:Blue; float y, <span style="color:Blue; float circleWidth)
{
<span style="color:Blue; bool ret = <span style="color:Blue; false;
<span style="color:Blue; using (GraphicsPath gPath = <span style="color:Blue; new GraphicsPath())
{
gPath.AddEllipse(<span style="color:Blue; new RectangleF(Point.X - circleWidth / 2F, Point.Y - circleWidth / 2F, circleWidth, circleWidth));
ret = gPath.IsVisible(x, y);
}

<span style="color:Blue; return ret;
}
[/code]




<img src="http://social.microsoft.com/Forums/getfile/49014/" alt=" <hr class="sig danieli

View the full article
 
Back
Top