Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may be experiencing this issue because your image is stretched in the PictureBox. You can verify this is the issue by setting the <code>SizeMode</code> property of the PictureBox to <code>Normal</code>.</p> <p>This is the sequence of events:</p> <ol> <li>The selection rectangle is drawn.</li> <li>The point/rectangle for the selection is determined.</li> <li>The unstretched image is retrieved from the PictureBox, and is passed to the Blur method, with the calculated rectangle.</li> <li>The unstretched image is blurred over the area described by the rectangle.</li> <li>The unstretched image, now blurred, is assigned to the PictureBox.</li> <li>The PictureBox stretches the image out to according to its <code>SizeMode</code> setting.</li> </ol> <p>This makes the image appear to have blurred in a different location than what you selected.</p> <p>The code you have looks at the selection rectangle, and uses those points to operate on the original image, not the stretched version of the image. If you want to blur the stretched image, you will need to get the stretched image first, then apply the blur to the rectangle selected on that image. Here is an example:</p> <pre><code> private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { //Right now I am using right click as a call to blur if (e.Button == MouseButtons.Right) { if (Rect.Contains(e.Location)) { pictureBox1.Image = Blur(getPictureBoxImage(), Rect, 5); pictureBox1.Refresh(); } } } private Bitmap getPictureBoxImage() { Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height); using (Graphics g = Graphics.FromImage(bmp)) { g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, bmp.Width, bmp.Height)); } return bmp; } </code></pre> <p>Code for retrieving the stretched image is derived from this answer: <a href="https://stackoverflow.com/a/8702405/935052">https://stackoverflow.com/a/8702405/935052</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload