在.NET中显示高分辨率图像? [英] Displaying high-res images in .NET?

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

问题描述

.. NET 1.1 / 2.0

我需要在.NET

应用程序(Windows窗体)中显示高分辨率可滚动图像。一个众所周知的解决方案是创建一个

面板,其AutoScroll设置为true。然后添加一个PictureBox或

另一个面板,用于显示图像。


但是,令我惊讶的是,上述方法有效,基于.NET GDI +

图形并不是真正的高分辨率友好。


请考虑以下代码示例:


1)

位图b =新位图(6000,6000);

panel2.BackgroundImage = b; //< - 工作正常


2)

位图b =新位图(14000,10000);

panel2 .BackgroundImage = b; //< - " Out of memory"错误

错误的完整堆栈是:


System.OutOfMemoryException:内存不足。

在System.Drawing。 TextureBrush..ctor(图片图片,WrapMode

wrapMode)

在System.Windows.Forms.Control.PaintBackground(Paint EventArgs e,

矩形矩形)

在System.Windows.Forms.Control.OnPaintBackground(Pai ntEventArgs

pevent)

at

System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e,

Int16 layer,Boolean disposeEventArgs)

at System.Windows.Forms.Control.WmEraseBkgnd(Message& m)

在System.Windows.Forms.Control.WndProc(消息& m)

在System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)<在System.Windows.Forms.ControlNativeWindow.OnMessage(消息& m)上的


在System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
System.Windows.Forms.NativeWindow.Callback(IntP。
) tr hWnd,Int32

msg,IntPtr wparam,IntPtr lparam)

在内部,TextureBrush构造函数调用

GdipCreateTexture()方法gdiplus.dll,显然,

对该方法可以处理的图像大小有一些限制。


显然,我达到了一定的限制GDI +在这里,但仍需要

找到解决方案。我想继续使用.NET,如果可能的话,避免使用

任何第三方ActiveX控件。


我可以选择哪些替代方案?

将使用.NET 3.x和WPF帮助吗?


TIA!

..NET 1.1/2.0

I have a need to display high-resolution scrollable images in a .NET
application (Windows Forms). One well known solution is to create a
Panel with AutoScroll set to "true" and then add a PictureBox or
another Panel to it, that is used to display the image.

The above approach works, however, to my surprise, .NET GDI+-based
graphics are not really hi-res friendly.

Consider the following codes examples:

1)
Bitmap b = new Bitmap( 6000, 6000 );
panel2.BackgroundImage = b; // <-- Works OK

2)
Bitmap b = new Bitmap( 14000, 10000 );
panel2.BackgroundImage = b; // <-- "Out of memory" error
The full stack of the error is:

System.OutOfMemoryException: Out of memory.
at System.Drawing.TextureBrush..ctor(Image image, WrapMode
wrapMode)
at System.Windows.Forms.Control.PaintBackground(Paint EventArgs e,
Rectangle rectangle)
at System.Windows.Forms.Control.OnPaintBackground(Pai ntEventArgs
pevent)
at
System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmEraseBkgnd(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
Internally, the TextureBrush constructor makes a call to
GdipCreateTexture() method in gdiplus.dll, and, apparently, there is
some limit on the image size that the method can handle.

Obviously, I am hitting some limit of GDI+ here, but still need to
find a solution. I want to stay with .NET, if possible and avoid using
any third-party ActiveX controls.

What alternatives can I pursue?
Will going with .NET 3.x and WPF help?

TIA!

推荐答案

这个问题没有真正的解决方案。 32位进程的地址限制为2 b / b $ g GB,但实际上.NET

程序中可用的内存限制要少一些。

GDI +不适合处理大型图像,当然,一张14000

乘以10000全彩色图像会达到略高于534的尺度

兆字节。


加载到内存中的图像可能分配的内存比图像文件大小多得多。这是因为图像本身可能保存在
内存中,然后光栅图像也保持在完全展开状态。

如果图片框是双倍的在那里缓存甚至可能有两份完整的

内存中的图像。


-

-

鲍勃鲍威尔[MVP]

Visual C#,System.Drawing


Ramuseco Limited .NET咨询
http://www.ramuseco.com


查找精彩的Windows窗体文章在Windows窗体提示和技巧中
http://www.bobpowell.net/ tipstricks.htm


用GDI + FAQ回答那些GDI +问题
http://www.bobpowell.net/faqmain.htm

所有新文章都提供C#和VB代码。 NET。

订阅e提供的RSS提要,绝不会错过任何新文章。

" Usenet User" < no ***** @ no.waywrote in message

news:a4 ************************* ******* @ 4ax.com ...
There are no real solutions to this problem. A 32 bit process has a 2
gigabyte address limit but in reality the usable limits of memory in a .NET
program are somewhat less.

GDI+ is not well suited to dealing with large images and certainly, a 14000
by 10000 full colour image would hit the scales at a little over 534
megabytes.

An image loaded into memory may have far more memory allocated to it than
just the image file size. This is because the image itself might be held in
memory and then the raster image is also held in it''s fully expanded state.
If the picture box is double buffered there may even be two full copies of
the image in memory.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Usenet User" <no*****@no.waywrote in message
news:a4********************************@4ax.com...

.NET 1.1 / 2.0

我有一个需要在.NET

应用程序(Windows窗体)中显示高分辨率可滚动图像。一个众所周知的解决方案是创建一个

面板,其AutoScroll设置为true。然后添加一个PictureBox或

另一个面板,用于显示图像。


但是,令我惊讶的是,上述方法有效,基于.NET GDI +

图形并不是真正的高分辨率友好。


请考虑以下代码示例:


1)

位图b =新位图(6000,6000);

panel2.BackgroundImage = b; //< - 工作正常


2)

位图b =新位图(14000,10000);

panel2 .BackgroundImage = b; //< - " Out of memory"错误


错误的完整堆栈是:


System.OutOfMemoryException:内存不足。

at System.Drawing.TextureBrush..ctor(图片图片,WrapMode

wrapMode)

在System.Windows.Forms.Control.PaintBackground(Paint EventArgs e,

矩形矩形)

在System.Windows.Forms.Control.OnPaintBackground(Pai ntEventArgs

pevent)

at

System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e,

Int16 layer,Boolean disposeEventArgs)

在System.Windows.Forms.Control。 WmEraseBkgnd(消息& m)

在System.Windows.Forms.Control.WndProc(消息& m)

在System.Windows.Forms.ScrollableControl.WndProc(Mes sage& ; m)

在System.Windows.Forms.ControlNativeWindow.OnMessage(消息& m)

在System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)

在System.Windows.Forms.N ativeWindow.Callback(IntPtr hWnd,Int32

msg,IntPtr wparam,IntPtr lparam)


在内部,TextureBrush构造函数调用

gdiplus.dll中的GdipCreateTexture()方法,显然,

对该方法可以处理的图像大小有一些限制。


显然,我在这里遇到了一些GDI +的限制,但仍然需要找到一个解决方案。我想继续使用.NET,如果可能的话,避免使用

任何第三方ActiveX控件。


我可以选择哪些替代方案?

将使用.NET 3.x和WPF帮助吗?


TIA!
.NET 1.1/2.0

I have a need to display high-resolution scrollable images in a .NET
application (Windows Forms). One well known solution is to create a
Panel with AutoScroll set to "true" and then add a PictureBox or
another Panel to it, that is used to display the image.

The above approach works, however, to my surprise, .NET GDI+-based
graphics are not really hi-res friendly.

Consider the following codes examples:

1)
Bitmap b = new Bitmap( 6000, 6000 );
panel2.BackgroundImage = b; // <-- Works OK

2)
Bitmap b = new Bitmap( 14000, 10000 );
panel2.BackgroundImage = b; // <-- "Out of memory" error
The full stack of the error is:

System.OutOfMemoryException: Out of memory.
at System.Drawing.TextureBrush..ctor(Image image, WrapMode
wrapMode)
at System.Windows.Forms.Control.PaintBackground(Paint EventArgs e,
Rectangle rectangle)
at System.Windows.Forms.Control.OnPaintBackground(Pai ntEventArgs
pevent)
at
System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmEraseBkgnd(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
Internally, the TextureBrush constructor makes a call to
GdipCreateTexture() method in gdiplus.dll, and, apparently, there is
some limit on the image size that the method can handle.

Obviously, I am hitting some limit of GDI+ here, but still need to
find a solution. I want to stay with .NET, if possible and avoid using
any third-party ActiveX controls.

What alternatives can I pursue?
Will going with .NET 3.x and WPF help?

TIA!


Bob Powell [MVP]写道:
Bob Powell [MVP] wrote:

这个问题没有真正的解决方案。 32位进程的地址限制为2 b / b $ g GB,但实际上.NET程序中可用的内存限制要少一些。
There are no real solutions to this problem. A 32 bit process has a 2
gigabyte address limit but in reality the usable limits of memory in
a .NET program are somewhat less.



至少,像MapViewOfFile这样的潜在解决方案并不是很容易获得来自C#的

At least, potential solutions such as MapViewOfFile aren''t very accessible
from C#.


>

GDI +并不适合处理大型图像,当然,一张价格高达44美元的全彩色图像将会达到一点点

超过534兆字节。


加载到内存中的图像可能会分配更多的内存

而不仅仅是图像文件大小。这是因为图像本身可能会在内存中保存,然后光栅图像也会保持在它的完全展开状态。如果图片框是双缓冲的,那么即使是内存中图像的两个完整副本也可能是

>
GDI+ is not well suited to dealing with large images and certainly, a
14000 by 10000 full colour image would hit the scales at a little
over 534 megabytes.

An image loaded into memory may have far more memory allocated to it
than just the image file size. This is because the image itself might
be held in memory and then the raster image is also held in it''s
fully expanded state. If the picture box is double buffered there may
even be two full copies of the image in memory.



4月24日下午6:04,Ben Voigt [C ++ MVP]" < r ... @nospam.nospamwrote:
On Apr 24, 6:04 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:

Bob Powell [MVP]写道:
Bob Powell [MVP] wrote:

如果图片框是双缓冲的,那么即使是内存中图像的两个完整副本也可能是

If the picture box is double buffered there may
even be two full copies of the image in memory.



图片框绝对是双缓冲的。我刚才有类似的

问题,解决方法是将容器从一个图片框更改为一个用户控件。

详细信息:
http://nomagichere.blogspot.com/2007...-creature.html

Marc

The picture box is definitely double buffered. I had a similar
problem a while ago, and the solution was to change the container
control from a picture box to a user control.

Details here:
http://nomagichere.blogspot.com/2007...-creature.html

Marc


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

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