0
我在使用此功能將圖像分成多個部分並稍微移動它們時遇到問題。如何使用drawImage()
問題在於,結果中矩形的高度與「node_height」變量不同。
這裏是一個測試圖像:measure.jpg ,其結果:measured.jpg 這個圖像I使用的 「node_height = 100」。它應該切割所有的圈子。
代碼:
private void button2_Click(object sender, EventArgs e)
{
bmp = new Bitmap(source.Width, source.Height);
bmp.SetResolution(source.HorizontalResolution, source.VerticalResolution);
int node_height = trackBar1.Value;
int shift = trackBar2.Value;
int image_width = bmp.Width;
int image_height = bmp.Height;
double division = image_height/node_height;
int nodes = Convert.ToInt32(division);
Graphics g = Graphics.FromImage(bmp);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
g.PageScale = 1;
g.PageUnit = GraphicsUnit.Pixel;
g.Clear(Color.Transparent);
for(var i = 0; i < nodes; i++) {
int new_shift = RandomNumber(0,shift);
int x = 0;
int y = node_height * i;
int w = image_width;
int h = node_height;
Rectangle source_rect = new Rectangle(x, y, w, h);
Rectangle dest_rect = new Rectangle(new_shift, y, w, h);
g.DrawImage(source, dest_rect, source_rect, GraphicsUnit.Pixel);
}
MessageBox.Show("Done!");
pictureBox1.Image = bmp;
}
你可以發佈它的實際外觀圖像嗎? – vesan