c # Move image without trace

0

I'm moving a picturebox over another with a mouse. But it leaves a trail behind when I move the mouse, the trail disappears right away, but is there a way to remove it?

I tried to take the refresh() when the image moves, it takes the trail but it locks too much, it moves very slowly, it stumbles.

Here is the code:

private void picImage_MouseMove(object sender, MouseEventArgs e)
    {

        if (picImage.Image == null)
            return;

        if(act)
        UpdateZoomedImage(e);

       picZoom.Location = new Point(e.X+40, e.Y+40);
       picZoom.Refresh();
    }

Zoom code:

private void UpdateZoomedImage(MouseEventArgs e)
    {
        // Calculate the width and height of the portion of the image we want
        // to show in the picZoom picturebox. This value changes when the zoom
        // factor is changed.
        int zoomWidth = picZoom.Width / _ZoomFactor;
        int zoomHeight = picZoom.Height / _ZoomFactor;

        // Calculate the horizontal and vertical midpoints for the crosshair
        // cursor and correct centering of the new image
        int halfWidth = zoomWidth / 2;
        int halfHeight = zoomHeight / 2;

        // Create a new temporary bitmap to fit inside the picZoom picturebox
        Bitmap tempBitmap = new Bitmap(zoomWidth, zoomHeight, PixelFormat.Format24bppRgb);

        // Create a temporary Graphics object to work on the bitmap
        Graphics bmGraphics = Graphics.FromImage(tempBitmap);

        // Clear the bitmap with the selected backcolor
        bmGraphics.Clear(_BackColor);

        // Set the interpolation mode
        bmGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

        // Draw the portion of the main image onto the bitmap
        // The target rectangle is already known now.
        // Here the mouse position of the cursor on the main image is used to
        // cut out a portion of the main image.
        bmGraphics.DrawImage(picImage.Image,
                             new Rectangle(0, 0, zoomWidth, zoomHeight),
                             new Rectangle(e.X - halfWidth, e.Y - halfHeight, zoomWidth, zoomHeight),
                             GraphicsUnit.Pixel);

        // Draw the bitmap on the picZoom picturebox
        picZoom.Image = tempBitmap;

        // Draw a crosshair on the bitmap to simulate the cursor position
        bmGraphics.DrawLine(Pens.Black, halfWidth + 1, halfHeight - 4, halfWidth + 1, halfHeight - 1);
        bmGraphics.DrawLine(Pens.Black, halfWidth + 1, halfHeight + 6, halfWidth + 1, halfHeight + 3);
        bmGraphics.DrawLine(Pens.Black, halfWidth - 4, halfHeight + 1, halfWidth - 1, halfHeight + 1);
        bmGraphics.DrawLine(Pens.Black, halfWidth + 6, halfHeight + 1, halfWidth + 3, halfHeight + 1);

        // Dispose of the Graphics object
        bmGraphics.Dispose();

        // Refresh the picZoom picturebox to reflect the changes
        picZoom.Refresh();
    }
    
asked by anonymous 16.08.2017 / 17:35

1 answer

1

I think the problem is, that at each point you move the mouse, you redraw the image completely, I would put a Timer to delay the drawing process, only running it once, at the end of the movement. p>     

16.08.2017 / 19:16