Windows Mobile-在CF.NET中按大小创建与设备无关的位图 [英] Windows Mobile - Creating a Device Independent Bitmap by Size in CF.NET

查看:45
本文介绍了Windows Mobile-在CF.NET中按大小创建与设备无关的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力处理渲染( OutOfMemoryException什么时候发生在CF.NET中创建大型位图)已有一段时间,而我仍在寻找解决问题的好方法.

I've been fighting with my rendering (OutOfMemoryException When Creating a Large Bitmap in CF.NET) for a while, and I'm still looking for a good way to fix my issues.

我的引擎创建了一个大的位图(比屏幕大小大2倍或3倍),并将所有内容绘制到该表面.然后,我将该图像以一定的偏移量绘制到屏幕上,从而允许用户非常平滑地滚动.

My engine creates a single large bitmap (2x or 3x bigger than the size of the screen), and draws everything to that surface. I then draw that image onto the screen at an offset, allowing the user to scroll VERY smoothly.

这在大多数情况下都有效,但是某些用户在创建较大的位图时会遇到OutOfMemoryExecptions.我已经完成作业,看来这是因为我正在创建设备相关位图(DDB),并且在Windows Mobile上,所有DDB以及所有其他应用程序位图都分配给了gwes.exe进程.如果该gwes.exe进程占用的内存超过32M,则会出现此异常.

This works great most of the time, but some users encounter OutOfMemoryExecptions when creating that large bitmap. I've done my homework and it appears that this is because I am creating a Device Dependant Bitmap (DDB), and on Windows Mobile all DDBs are assigned to the gwes.exe process, along with every other apps bitmaps. If that gwes.exe process takes up more than 32M, you get this exception.

我确实看到与设备无关的位图(DIB)实际上是在您自己的进程空间中创建的,而不是分配给gwes.exe的.由于在达到32M的过程中还有更多的空间,所以我想我会探索这种可能性的.

I do see that Device Independent Bitmaps(DIB) are actually created in your own process space, rather than be assigned to gwes.exe. Since I have way more room before reaching 32M in my process, I thought I'd explore this possibility.

但是我发现创建DIB的唯一方法是通过从流(如现有文件)创建位图.我想不通任何方法可以从头开始创建一个,并指定我希望它是1280x240和256色.

But the only way I can find to create a DIB is through creating a bitmap from a stream, like an existing file. I can't figure out any way to create one from scratch and specify that I want it to be 1280x240 with 256 colors.

有人知道该怎么做吗?

推荐答案

当我创建从Pocket PC打印到蓝牙打印机的自定义报告时,我不得不做类似的事情.我必须生成一张纸大小的位图,然后将其流式传输到打印机,并且所有使用受管理对象执行此操作的尝试都会不断遇到内存问题,就像您看到的那样.

I had to do something similar to this a while back when I was creating custom reports printed from a Pocket PC to a bluetootch printer. I had to generate bitmaps the size of a piece of paper, then stream that to the printer, and all attempts to do that with a managed object kept hitting memory issues like you're seeing.

我做了什么(很抱歉,我无法直接给您提供有关此内容的信息):

What I did (sorry I can't give you the direct source on this one):

您现在拥有一个HDC,并且可以从中调用

You now have an HDC, and from that you can call Graphics.FromHdc.

通过这种方式,您可以在自己的进程中拥有所有功能(实际上,如果使其足够大,它将来自共享内存,并且完全避免了32MB的处理空间).

This way you have all of it in your own process (and in fact if you make it big enough, it will come from shared memory and avoid the 32MB process space altogether).

这篇关于Windows Mobile-在CF.NET中按大小创建与设备无关的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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