在.NET中的COM preSS图像 [英] Compress image in .NET

查看:189
本文介绍了在.NET中的COM preSS图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何COM preSS和在C#中的图像文件( BMP,的JPEG) 我有,使用IM以下code扩展我的形象来显示一些图片作为背景在我的控制

How can i compress and image file(bmp,jpeg) in C#, I have to display some images as background on my controls, i m using following code to scale my image

Bitmap orgBitmap = new Bitmap(_filePath);
Bitmap regBitmap = new Bitmap(reqSize.Width, reqSize.Height);

 using (Graphics gr = Graphics.FromImage(reqBitmap))
 {
  gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  gr.DrawImage(bmp, new RectangleF(0, 0, reqSize.Width, reqSize.Height));
  }

这给了我所需要的位图。 我的问题是,如果原单位是重(2 MB),然后当我加载50个图像它喂我所有的记忆,我想COM preSS的形象多少,我可以在不丢失这么多的质量问题,我该怎么办在.NET一样吗?

It giving me the required bitmap. My problem is if orginal bitmap is to heavy(2 MB) then when i load 50 image it feed all my memory, i want to compress the image as much i can without losing the so much quality,How can i do the same in .NET ?

推荐答案

你肯定需要大量的图像是present在执行时?使用图像编辑软件(Photoshop中,油漆车间专业等),事先你能调整它们的大小(或者将其保存在质量稍差)?似乎有一点一点做的工作每次运行时 - 尤其是编辑工具有可能做得更好呢

Do you definitely need the large images to be present at execution time? Could you resize them (or save them at a slightly lower quality) using an image editing program (Photoshop, Paintshop Pro etc) beforehand? There seems to be little point in doing the work every time you run - especially as editing tools are likely to do a better job anyway.

当然,这也不会,如果是像从他们的硬盘上挑选任意图像的用户使用。

Of course, this won't work if it's something like the user picking arbitrary images from their hard disk.

另外一点:你在处理位图,当你与他们就完蛋了?你是不是表明在code ...如果你不处理原来的(大),位图,那么你会在终结来释放非托管资源的支配。该终结也将延缓这些对象的垃圾回收。

Another point: are you disposing of the bitmaps when you're finished with them? You aren't showing that in your code... if you're not disposing of the original (large) bitmaps then you'll be at the mercy of finalizers to release the unmanaged resources. The finalizers will also delay garbage collection of those objects.

这篇关于在.NET中的COM preSS图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆