用C#读取大图像 [英] Read Large Images in C#

查看:135
本文介绍了用C#读取大图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在我的应用程序中,我需要显示一些大小约800MB的大图像。



当我尝试使用

Hi All,

In my application i need to display some large images which are having size of about 800MB.

When im trying to read the Image Using

Image img = Image.FromFile(filepath);

显示OutOfMemory错误时读取图像。



请帮帮我。如何阅读大图?

its showing OutOfMemory error.

Please help me. How to read large Images?

推荐答案

情况根本不容易。这是一个想法:



拿一台有足够内存的电脑,你可以阅读它。重要提示:在此阶段,您应使用未压缩的图像。将大图像分成N x M个较小片段的一些易于管理的大小,并将这些片段作为单独的文件安全。



选择不同大小的同一图像并进行缩放使用2-3个或更多不同的比例因子。像素的最小尺寸应该是一些相当小的计算机显示器或更小的尺寸。您应该能够一次以最小的分辨率加载整个文件。重新对您的图像进行采样,将其缩小到该组较低的分辨率。至于更高分辨率的步骤,您可能还需要将图像分成较小的碎片。



通过这种方式,您将拥有不同的所有单个图像尺寸,像素和一些较高分辨率等级的尺寸将显示为较小图像的矩阵。



您永远不需要以全分辨率显示整个图像,因为无论如何屏幕​​尺寸都不允许。您需要选择一组大小,以便为每个给定的分辨率和用户请求的视图端口生成虚拟映像。该技术应该类似于Google Earth的呈现技术。你算数学吗?如果你做得对,你的虚拟图像的每个视图一次只需要不超过4个图像矩阵片段。



唯一的问题是图像压缩。如果使用像JPEG这样强大的有损压缩,则可以看到片段之间边缘的伪像。通过更多压缩,您无论如何都会在图像上看到伪影。所以,如果你适度压缩,我认为你仍然可以使用有损压缩。



此外,仅在最后一步进行压缩。您的源代码应该是未压缩的(使用无损压缩是最好的)。你的最终结果应该只被压缩一次,总是重新从头开始重做不令人满意的结果,从一个无丢失的图像。重复压缩相同的图像往往会累积伪影和其他缺陷。



-SA
The situation is not easy at all. Here is some idea:

Take a computer which has enough memory where you can read it. Important: on this stage, you should use uncompressed images. Break the big image into N x M of smaller fragments of some easily managed size and safe these fragments as separate files.

Select different size of the same image and scale it down using 2-3 or more different scale factors. The smallest size of the image in pixels should be of the size of of some fairly small computer monitor or less. You should be able to load the whole file in the smallest resolution at once. Re-sample you image, scaling it down to that set of lower resolutions. As to the higher resolution steps, you might need to break the image in smaller fragments, too.

In this way, you will have all of your single image in different sizes, in pixels, and some sizes of higher resolution levels will be presented as a matrix of smaller images.

You never need to show the whole image in full resolution, because the screen size will not allow it anyway. You need to select the set of sized the way you can produce a "virtual image" for every given resolution and the view port requested by the user. The technique should resemble the technique of presentation of the Google Earth. Do you math. If you do it right, every view of your "virtual image" will need no more than 4 fragments of the image matrix at a time.

The only problem is image compression. If you use strong lossy compression like JPEG, you can see artifact of the edges between fragments. With more compression, you will see artifacts on the image anyway. So, I think you still can use lossy compression if you compress moderately.

Also, make compression only on the last step. You source code should be uncompressed (it''s the best to use lostless compression). You final result should be compressed only once, always redo unsatisfactory results from scratch, from a lostless image. Repeated compression of the same image tend to accumulate artifacts and other defects.

—SA


如果.NET不支持这个大小,你可能需要自己打开并解释文件内容。



它们的格式是什么?



(您的问题可能有很多答案,请提供更多意见。)
If .NET does not support this size, you''ll probably have to open and interpret the file content yourself.

What format are they ?

(There may be many answers to your question, please provide more input.)


这篇关于用C#读取大图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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