我在使用此函数将图像分成多个部分并稍微移动它们时遇到了问题。
问题是在结果中矩形的高度与"node_height“变量不同。
这是一个测试图像:measure.jpg和结果:measured.jpg在此图像中,我使用了"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;
}发布于 2015-06-09 14:23:16
我设法解决了这个问题。我在随机序列中得到了相等的数字。以下是我的案例Problem in generating random number中的解决方案的链接
https://stackoverflow.com/questions/30722860
复制相似问题