I’m loading layers of images to make a single image. I’m currently stacking them all onto a canvas. I’ve got it set up so the user can specify the final dimensions of the single image, but even when I change the size of the canvas the images retain their original sizes.
I tried to modify the image size as I was loading them in, but the sizes were NaN and the Actual Sizes were 0 so I couldn’t change them there.
I’m starting to think that canvas might not be the way to go. Any suggestions to how I could clip images to fit a specific size?
canvas1.Children.Clear();
int totalImages = Window1.GetNumberOfImages();
if (drawBackground)
canvas1.Background = new SolidColorBrush(Color.FromArgb(a,r,g,b));
else
canvas1.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
for (int i = 0; i < totalImages; i++)
{
Image image = new Image();
image.Source = Window1.GetNextImage(i);
canvas1.Children.Add(image);
}
To get the current sizes of the canvas, you must first call
MeasureandArrange. This will avoid the NaNs and 0s.Use
RenderTransformto change the size of the image that the Canvas displays.I have never tried to crop an image, so I don’t know how to do that, but I see that there is a CroppedBitmap object. I guess you tried that already?