English 中文(简体)
c # #(或任何其他压缩格式)
原标题:c# saving very large bitmaps as jpegs (or any other compressed format)

I am currently handling very large images, which are basically generated by stitching together many smaller images (e.g. panorama or photo mosaic software). In order to avoid out-of-memory exceptions (in memory are only "maps" of how to arrange the smaller images), I wrote some code saving these images line by line as bitmaps using BinaryWriter and LockBits. So far, so good.

现在的问题是,我也希望将这些形象作为吉卜赛人(或巴布亚新几内亚)拯救出来。 自2006年以来 我认为,现在只有两种途径:

(1) 类似于图纸储蓄程序。 形成一些 j头并按行节约大图像线,在以前压缩大图像。 但我对如何执行压缩意见没有任何想法。

(2) 将已节省的借方图翻译成存储器,并作为编码分类予以保存。

由于第二种做法似乎比较容易,我尝试了这样的办法:

FileStream fsr =
    new FileStream("input.bmp", FileMode.Open, FileAccess.Read);
FileStream fsw =
    new FileStream("output.jpg", FileMode.CreateNew, FileAccess.Write);

EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] =
    new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L);

Bitmap bmp = new Bitmap(fsr);
bmp.Save(fsw, GetEncoder(ImageFormat.Jpeg), encoderParameters);
bmp.Dispose();

现在的问题是,“节省费用的方法”首先试图将借方地图完全装入记忆中,从而造成非主题性的例外。

我非常乐于就如何解决或绕过这一问题提出任何建议。

问题回答

注:JPEG压缩有一些重要的非排泄缺陷:

1) JPEG is lossy, so you will not regenerate the same image. This might be perfectly acceptable, but if you need to exactly regenerate source image, then PNG is the way to go.

2) 联合项目在8-9轴边界上进行了调整。 如果你把大小不是8个以上的图像混为一谈,那么你就会在图像界获得一些强大的手工艺品。

考虑到你的使用情况,我建议把“亮”而不是的itch图像合在一起,并使用标准压缩算法,如PNG或Zlib,对每个较小的形象。 您仍可将由此压缩的溪流存入单一档案。 好处是,你可以直接“放弃”你想要拍摄的小形象,这将节省许多记忆。

不利之处是,你不能把所有较小的图像“视像审查”变成一个大的单一图像(你将需要为这种使用制定方案)。

我怀疑你在互联网上这样做,但你总是可以打电话到C图书馆做重提。 我有自己的用 t,但我建议你看GraphicsMagick 图书馆。 它拥有一个C图书馆,拥有许可,允许公开来源和商业使用,它像你那样做。

(因为标题是“或任何其他压缩格式”)

TIFF format has a notion of tiles and stripes. Both can be used to avoid having all the big image in memory at any time. Maybe tiles will come in handy for you since you are stitching small images.

您可尝试LibTiff.Net(自由、商业友好、公开来源,仅用C#撰写)。

有一个条款: rel=“nofollow noreleaseer”>:Basic introduction to the capacity of the Library with information about abolition- and less-direct concept IO (in the second part of the article)。

申斥: 我为该公司工作。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签