1

I am trying to load an image onto a usercontrol Graphics Surface. I have no problem doing this. However, the result is never as expected. The image should scale to reach the border with the longest axis and be in the center of the remaining axis. I can not find any information that describes this relationship well to enable full understanding of what is actually happening.

Using something like :

private void ZoomControl_Paint(object sender, PaintEventArgs e)
{
   var g = e.Graphics;
   g.Transform = new Matrix();
   Zoom = 0.5;
   float X = dx;
   float Y = dy;
   g.TranslateTransform(X, Y);
   g.ScaleTransform(zoom, zoom);
   g.DrawImage(objBitmap, 0,0);
}

I have tried many combinations but all this is doing is proofing I don't know how a transformation works and its persistence nature.

I can scale correctly using Image methods and paint normaly on the control for the perfect solution but this does not yield a good starting point for Zooming and Panning to follow. Expected Result

This approach provides the best animation in the Drag and Zoom phases and the inspiration of this attempt was sourced here https://github.com/AliAlAali/ZoomPanControl. Sadly this example doesn't use or start with a perfectly scaled and centered image.

4
  • You are not using a PictureBox to show the image? It has a SizeMode property.
    – Clemens
    Commented Jul 10 at 6:36
  • You prepare th Graphics object but never use it to DrawImage.
    – TaW
    Commented Jul 10 at 7:20
  • TaW - This snippet of code is not real but is indicative of what is required. I can Draw the image, its just never as shown in the Expected Results link above. It is usually scaled smaller and bits are off the visible graphics surface. Commented Jul 11 at 17:55
  • Clemens - Using a Picturebox would be just too easy. My first 2 attempts to Zoom and Pan was with the picture box and this was too slow, the animation would flicker. The Transforms approach is the way to go, without a doubt. Commented Jul 11 at 18:01

0

Browse other questions tagged or ask your own question.