c# - Resize and Fit Image in WPF -
i have following:
using (bmp == new bitmap(50, 50)) { using (g == graphics.fromimage(bmp)) { g.interpolationmode = drawing2d.interpolationmode.highqualitybicubic; g.drawimage(img, 0, 0, 50, 50); } }
the user provides app image app has resize , fit entire image.
the problem above code stretches image, not fit (as 4:3 movie fits in widescreen tv leaving blackbars).
does have solution this? also, prefer not use gdi.
you need take size of input image account. here code snippet should right direction:
int x1 = 0, y1 = 0, x2 = 50, y2 = 50; if (img. width <= img.height) { // compute x1, y1 fit img horizontally bmp } else { // compute y1, y2 fit img vertically bmp } g.drawimage(img, x1,y1, x2,y2);
also notice asking resizing image in wpf using system.drawing uses gdi+ under hood.
Comments
Post a Comment