找回密码
 立即注册

QQ登录

只需一步,快速开始

13573156105

注册会员

6

主题

20

帖子

190

积分

注册会员

积分
190
13573156105
注册会员   /  发表于:2019-3-8 16:53  /   查看:3250  /  回复:7
   图像四周加边,我这样创建的图像,destImage保存后的分辨率,变小了,原来是300,现在成了150了,什么原因?非常感谢!!!!


             RasterCodecs codec = new RasterCodecs();
                // Load the image
                RasterImage image0 = codec.Load(this.textBox1.Text);
                // Creates a new image in memory with same dimensions as the source image
                RasterImage destImage = new RasterImage(
                   RasterMemoryFlags.Conventional,// None  Conventional
                   image0.Width + (2 * edge),
                   image0.Height + (2 * edge),
                   image0.BitsPerPixel,//BytesPerLine    BitsPerPixel
                   image0.Order,
                   image0.ViewPerspective,
                   image0.GetPalette(),
                   IntPtr.Zero,
                   0);
                image = destImage;
                // 填充图像颜色
                FillCommand command = new FillCommand();
                command.Color = new RasterColor(this.label6.BackColor.R, this.label6.BackColor.G, this.label6.BackColor.B);
                command.Run(image);

                RasterCodecs codecs3 = new RasterCodecs();
                codecs3.ThrowExceptionsOnInvalidImages = true;
                // Prepare the command
                CombineCommand command0 = new CombineCommand();
                myrect.X = edge; myrect.Y = edge; myrect.Width = image0.Width; myrect.Height = image0.Height;
                SizeCommand command1 = new SizeCommand();
                command1.Width = myrect.Width;
                command1.Height = myrect.Height;
                command1.Flags = RasterSizeFlags.None;


                command1.Run(image0);
                command0.SourceImage = image0;
                // the rectangle that represents the affected area of the destination image.
                command0.DestinationRectangle = myrect;

                command0.Run(image);

7 个回复

倒序浏览
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-3-8 18:10:11
沙发
这个我验证后给你答复
回复 使用道具 举报
13573156105
注册会员   /  发表于:2019-3-11 10:52:17
板凳
Richard.Ma 发表于 2019-3-8 18:10
这个我验证后给你答复

                RasterImage destImage = new RasterImage(
                   RasterMemoryFlags.Conventional,// None  Conventional
                   image0.Width + (2 * edge),
                   image0.Height + (2 * edge),
                   image0.BitsPerPixel,//BytesPerLine    BitsPerPixel
                   image0.Order,
                   image0.ViewPerspective,
                   image0.GetPalette(),
                   IntPtr.Zero,
                   0);
这样处理后的图片,分辨率都改为150,即使分辨率低于100的,也统一改为150,不知道是什么原因,望版主给予指导,非常感谢!!!
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-3-11 12:03:25
地板
您能发我完整的项目吗,或者一个示例项目,可以更快的确认问题
回复 使用道具 举报
13573156105
注册会员   /  发表于:2019-3-11 14:53:07
5#
本帖最后由 13573156105 于 2019-3-11 14:58 编辑
Richard.Ma 发表于 2019-3-11 12:03
您能发我完整的项目吗,或者一个示例项目,可以更快的确认问题

            RasterCodecs codec = new RasterCodecs();
                // Load the image
                RasterImage image0 = codec.Load("D:\001.jpg");
                // Creates a new image in memory with same dimensions as the source image
                RasterImage destImage = new RasterImage(
                   RasterMemoryFlags.Conventional,// None  Conventional
                   image0.Width + 10,
                   image0.Height +10,
                   image0.BitsPerPixel,//BytesPerLine    BitsPerPixel
                   image0.Order,
                   image0.ViewPerspective,
                   image0.GetPalette(),
                   IntPtr.Zero,
                   0);
                // 保存图像
                RasterCodecs codecs = new RasterCodecs();
                codecs.ThrowExceptionsOnInvalidImages = true;
                codecs.Options.Jpeg.Save.QualityFactor = 25;// min 0 or 2 and max 255   
                codecs.Save(destImage , "D:\002.jpg", RasterImageFormat.Jpeg422, 0);

随便找个图片,处理完后,分辨率全部是150
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-3-11 18:01:21
6#
按照您的代码,只需要在保存前设置dpi属性即可
  1.             destImage.XResolution = 300;
  2.             destImage.YResolution = 300;
复制代码
回复 使用道具 举报
13573156105
注册会员   /  发表于:2019-3-12 09:21:12
7#
Richard.Ma 发表于 2019-3-11 18:01
按照您的代码,只需要在保存前设置dpi属性即可

非常感谢!!
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-3-12 09:57:07
8#
不客气
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部