我有图像文件,我想裁剪并加载到picturebox
。当我远程下载它 - 一切正常,但是当我从本地机器加载它时 - picturebox
图片拉伸......
var img = (Bitmap) Image.FromStream(new WebClient().OpenRead("https://i.snag.gy/MjJca5.jpg"));
img = CropImage(img);
BackgroundImage = img;
BackgroundImageLayout = ImageLayout.Zoom;
public Bitmap CropImage(Image img) {
// create a graphic path to hold the shape data
GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
var points = new Point[] {
new Point(85, 1111), new Point(934, 1111), new Point(934, 952), new Point(1642, 952),
new Point(1642, 2000), new Point(85, 2000), new Point(85, 1111)
};
GraphicsPath gp = new GraphicsPath();
gp.AddPolygon(points.ToArray());
Bitmap bmp1 = new Bitmap(2220, 2220);
using(Graphics G = Graphics.FromImage(bmp1)) {
G.Clip = new Region(gp);
G.DrawImage(img, 0, 0);
bmp1.Save("axi.jpeg");
return bmp1;
}
}
此代码返回此图片。一切正常
但是此代码返回此图片。
FileStream file = new FileStream(openFileDialog1.FileName, FileMode.Open);
var img = (Bitmap) Image.FromStream(file);
img = CropImage(img);
pictureBox1.BackgroundImage = img;
pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
...