c# - Resize an image in a PictureBox to as large as it can go, while maintaining aspect ratio? -
I am trying to create it so that an image in the picture box control will automatically adjust the size based on its size Keep the window but aspect ratio so far, just setting the Is it possible to maintain aspect ratio, but still the image can go dynamically to spread large, because the form size changes? Is it possible to do this and is it still focused? I think that every time I change the size of the window, I can recreate the image in memory, but it looks like a bad idea. I believe that this has its effect Documentation says that: You also set it to property, the "comment" section of the documentation of that function also says: The picture box fits using the zoom value To cause the image to stretch or shrink; However, aspect ratio is maintained in the original. You can of course set the property to If it does not do exactly what you want, then you can always implement your resizing logic. Your concern is that every time the image resizes in memory, the size of control changes, "I feel like a bad idea", but I'm not sure why this is why you feel that the only problem will be when you are old < Code> bitmap were not careful to destroy unused graphics objects. These objects not only have underneath resources that need to be freed, you have a lot of memory The volume will start to put pressure on you to make them leak. Alternatively, to avoid creating a temporary bitmap, you can do pictureback control internally and use the pull-down method. If you pass a rectangle it will automatically scale the image to fit inside the rectangle. SizeMode to
StretchImage spreads the image to fit into the whole picturebox control, ignoring this aspect ratio. That's what I do not want.
< P> The size of the image has increased or the size ratio has decreased.
PictureBox.SizeMode in the property's properties window or in the code (eg, in the constructor of your form): < / P>
myPictureBox.SizeMode = PictureBoxSizeMode.Zoom;
Comments
Post a Comment