-3
私はこの写真を持っています(この画像はX:467 Y:300です)私はXから必要があります:0 Y:0 X:200 Y :45私は、作物のためにこのコードを使用しかし、私はXデータをロスト:0、Y:0をX:200 Y:45に私はあなたがしたいことを理解し、コメントから画像のXとYを設定するには画像を保存するにはC#
bmp.Save("@image.png", ImageFormat.Png);
Image img = new Bitmap("@image.png");
Rectangle source = new Rectangle(0, 0, ww, hh);
Image cropped = CropImage(img, source);
cropped.Save(Path.GetDirectoryName("@image.png") + "croppped" + Path.GetExtension("@image.png"));
}
private Bitmap CropImage(Image originalImage, Rectangle sourceRectangle,Rectangle? destinationRectangle = null)
{
if (destinationRectangle == null)
{
destinationRectangle = new Rectangle(Point.Empty, sourceRectangle.Size);
}
var croppedImage = new Bitmap(destinationRectangle.Value.Width,
destinationRectangle.Value.Height);
using (var graphics = Graphics.FromImage(croppedImage))
{
graphics.DrawImage(originalImage, destinationRectangle.Value,
sourceRectangle, GraphicsUnit.Pixel);
}
return croppedImage;
}
「CropImage」はうまく機能しているようです。これは実際のコードですか、あるいは矩形のパラメータに異なる値を指定していますか? –
@ C.Evenhuisはいこれが私のオリジナルコードですオリジナルイメージを使わずにイメージを作る方法はありますか? – amir
@ C.Evenhuisその働きはあるものの、データを失ったいくつかhow – amir