-
Jul 28th, 2017, 10:37 AM
#1
Thread Starter
Hyperactive Member
How to find the size of a Bitmap on a canvas?
Okay, I've got a canvas sized at 800 x 600, and I want to read in a bitmap and place it on the canvas. This works fine, and I've got the stretch property set to "Uniform"... so the bitmap grows/shrinks to fit the canvas, but retains the original aspect ratio. All of this works fine, but is there a way to find out what the bitmap dimensions are after it is resized by the uniform stretch?
I load the jpg into a bitmap image:
Code:
String myImageFile = @"C:\MyFolder\MyImage.jpg";
BitmapImage myBitmap = new BitmapImage();
myBitmap.BeginInit();
myBitmap.UriSource = new Uri(myImageFile, UriKind.Absolute);
myBitmap.EndInit();
Then I place the bitmap on the canvas:
Code:
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = myBitmap;
imageBrush.Stretch = Stretch.Uniform;
imgCanvas.Background = imageBrush;
Here's the issue. Because it retains the aspect ratio of the original image during the stretch, which is quite likely to be different from the aspect ratio of the canvas, there are probably going to be unused portions of the canvas. Later, when the user is clicking on the canvas to add elements to it (which also works fine), I don't want to let him/her click outside of the image area.
So, how do I find out the new, uniform stretched, size of the bitmap?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|