.NET GDI +图像大小 - 文件codeC的限制 [英] .NET GDI+ image size - file codec limitations

查看:92
本文介绍了.NET GDI +图像大小 - 文件codeC的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有图像的大小,可以连接$ C $使用光盘映像文件codeCS可从.NET限制?

我试图连接code图像> 4GB的大小,但它根本不起作用(或不能正常工作,即写出不可读文件).BMP,.JPG,png格式或。 TIF EN codeRS。

当我降低图像的大小到< 2GB它与.JPG而不是.BMP,.TIF或.png工作。

我的下一个尝试是尝试的libtiff因为我知道TIFF文件都是针对高画质图像。

什么是大的图像好的文件格式?还是我刚才碰到文件格式的限制?

(所有这些都是使用x64体系结构正在做在64位操作系统(操作系统64)的W RAM / 8 GB和编译。)

 随机R =新的随机((INT)DateTime.Now.Ticks);

INT宽度= 64000;
INT高= 64000;
INT跨距=(宽%4)> 0?宽+(宽%4):宽度;
UIntPtr数据大小=新UIntPtr((ULONG)步幅*(ULONG)高度);
IntPtr的P = Program.VirtualAlloc(IntPtr.Zero,数据大小,Program.AllocationType.COMMIT | Program.AllocationType.RESERVE,Program.MemoryProtection.READWRITE);

BMP位图=新位图(宽度,高度,跨度,PixelFormat.Format8bppIndexed,P);
的BitmapData BD = bmp.LockBits(新的Rectangle(0,0,bmp.Width,bmp.Height),ImageLockMode.ReadWrite,bmp.PixelFormat);

ColorPalette CP = bmp.Palette;
的for(int i = 0; I< cp.Entries.Length;我++)
{
  cp.Entries [I] = Color.FromArgb(我,我,我);
}
bmp.Palette = CP;

不安全
{
  对于(INT Y = 0; Y< bd.Height; Y ++)
  {
    字节*行=(BYTE *)bd.Scan0.ToPointer()+(Y * bd.Stride);
    为(中间体X = 0 X  - 其中; bd.Width; X ++)
    {
      *(行+ X)=(字节)r.Next(256);
    }
  }
}

bmp.UnlockBits(BD);
bmp.Save(@C:\ test.jpg放在ImageFormat.Jpeg);
bmp.Dispose();

Program.VirtualFree(P,UIntPtr.Zero,为0x8000);
 

我也尝试过使用一个固定的GC存储区域,但这是有限的到< 2GB。

 随机R =新的随机((INT)DateTime.Now.Ticks);

INT bytesPerPixel = 4;
INT宽= 4000;
INT高= 4000;
INT填充= 4  - ((宽度* bytesPerPixel)%4);
填充=(填充== 4?0:填充);
INT跨距=(宽* bytesPerPixel)+填充;
UInt32的[]像素=新UInt32的[宽*​​高]。
的GCHandle gchPixels = GCHandle.Alloc(像素,GCHandleType.Pinned);
使用(BMP位图=新位图(宽度,高度,跨度,PixelFormat.Format32bppPArgb,gchPixels.AddrOfPinnedObject()))
{
    对于(INT Y = 0; Y<高度; Y ++)
    {
        INT行=(Y *宽);
        对于(INT X = 0,X<宽度; X ++)
        {
            像素[行+ X] =(UINT)r.Next();
        }
    }

    bmp.Save(@C:\ test.jpg放在ImageFormat.Jpeg);
}
gchPixels.Free();
 

解决方案

所以,你的目标是要连接code成JPEG?我相信会有办法拉只有你在编码的部分,然后释放并继续下一部分。如果你打开​​文件原和分析自己,我相信有JPEG EN codeRS都来帮助创建了部分开源。这应该允许您连接code文件非常大,但你永远有操作系统和文件系统的困难需要克服。

Is there a limit on the size of image that can be encoded using the image file codecs available from .NET?

I'm trying to encode images > 4GB in size, but it simply does not work (or does not work properly i.e. writes out an unreadable file) with .bmp, .jpg, .png or the .tif encoders.

When I lower the image size to < 2GB it does work with the .jpg but not the .bmp, .tif or .png.

My next attempt would be to try libtiff because I know tiff files are meant for large images.

What is a good file format for large images? or am I just hitting the file format limitations?

(All of this is being done on a 64 bit operating system (WinXP 64) w/ 8 GB of RAM and compiled using x64 architecture.)

Random r = new Random((int)DateTime.Now.Ticks);

int width = 64000;
int height = 64000;
int stride = (width % 4) > 0 ? width + (width % 4) : width;
UIntPtr dataSize = new UIntPtr((ulong)stride * (ulong)height);
IntPtr p = Program.VirtualAlloc(IntPtr.Zero, dataSize, Program.AllocationType.COMMIT | Program.AllocationType.RESERVE, Program.MemoryProtection.READWRITE);

Bitmap bmp = new Bitmap(width, height, stride, PixelFormat.Format8bppIndexed, p);
BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);

ColorPalette cp = bmp.Palette;
for (int i = 0; i < cp.Entries.Length; i++)
{
  cp.Entries[i] = Color.FromArgb(i, i, i);
}
bmp.Palette = cp;

unsafe
{
  for (int y = 0; y < bd.Height; y++)
  {
    byte* row = (byte*)bd.Scan0.ToPointer() + (y * bd.Stride);
    for (int x = 0; x < bd.Width; x++)
    {
      *(row + x) = (byte)r.Next(256);
    }
  }
}

bmp.UnlockBits(bd);
bmp.Save(@"c:\test.jpg", ImageFormat.Jpeg);
bmp.Dispose();

Program.VirtualFree(p, UIntPtr.Zero, 0x8000);

I have also tried using a pinned GC memory region, but this is limited to < 2GB.

Random r = new Random((int)DateTime.Now.Ticks);

int bytesPerPixel = 4;
int width = 4000;
int height = 4000;         
int padding = 4 - ((width * bytesPerPixel) % 4);
padding = (padding == 4 ? 0 : padding);
int stride = (width * bytesPerPixel) + padding;
UInt32[] pixels = new UInt32[width * height];
GCHandle gchPixels = GCHandle.Alloc(pixels, GCHandleType.Pinned);
using (Bitmap bmp = new Bitmap(width, height, stride, PixelFormat.Format32bppPArgb, gchPixels.AddrOfPinnedObject()))
{
    for (int y = 0; y < height; y++)
    {
        int row = (y * width);
        for (int x = 0; x < width; x++)
        {
            pixels[row + x] = (uint)r.Next();
        }
    }

    bmp.Save(@"c:\test.jpg", ImageFormat.Jpeg);
}
gchPixels.Free();

解决方案

So your goal is to encode them into jpeg? I am sure there would be a way to pull in only the section you are encoding, then dispose and go on to the next section. If you open the file raw and and parse it yourself, I am sure there are open source jpeg encoders out there to help with creating the sections. This should allow you to encode files extremely large, but your will always have OS and filesystem hurdles to overcome.

这篇关于.NET GDI +图像大小 - 文件codeC的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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