首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用drawImage()

如何使用drawImage()
EN

Stack Overflow用户
提问于 2015-06-09 12:10:51
回答 1查看 76关注 0票数 0

我在使用此函数将图像分成多个部分并稍微移动它们时遇到了问题。

问题是在结果中矩形的高度与"node_height“变量不同。

这是一个测试图像:measure.jpg和结果:measured.jpg在此图像中,我使用了"node_height = 100“。它应该把所有的圆圈都剪掉。

代码:

代码语言:javascript
复制
    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;
    }
EN

回答 1

Stack Overflow用户

发布于 2015-06-09 14:23:16

我设法解决了这个问题。我在随机序列中得到了相等的数字。以下是我的案例Problem in generating random number中的解决方案的链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30722860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档