开发者

Large bitmap maniuplation in WPF

开发者 https://www.devze.com 2023-02-01 23:14 出处:网络
Is WPF be able to manipulate large bitmaps where GDI+ cannot due to memory limitations? I have b开发者_运维技巧itmaps that are 10,000x10,000 easily, and could even be much larger than that. Worst cas

Is WPF be able to manipulate large bitmaps where GDI+ cannot due to memory limitations?

I have b开发者_运维技巧itmaps that are 10,000x10,000 easily, and could even be much larger than that. Worst case I think I can break the single bitmap into large tiles and work with that I guess.

I basically need to do four things

  1. Take an set of tiled images
  2. Put all of those tiles into a single bitmap
  3. Convert the bitmap to black and white
  4. Scan the bitmap looking for changes from black to white

I know how to do these things in GDI+, but the problem I am running into is that the size of my bitmap is too large for the machine I am using, and it causes the program to crash, and I cannot make the image any smaller, so I am hoping that WPF will be able to succeed where GDI+ has failed me.


I don't think WPF will be able to help you here.

Why do you want to use bitmap object? You may as well work with an two-dimensional array of bytes or doubles (or any other type, depending oh what accuracy and range do you need), especially if you work with one channel only. Bitmaps have accessor methods (GetPixel and such) with huge computational overhead, working with arrays is by orders of magnitude faster (I know from personal experience), the only issue is that you can't display them as they are (you would have to convert the array back into image, which is fairly simple). But since you seem to want to do some sort of analysis on the data, I think array would be much more suitable for your needs.

I can post code samples detailing conversion from bitmap (either WPF or WinForms) to array an back if you want.

But remember, that 32bit .NET application can use approximately 1.2-1.4 gigabytes of memory - you have to fit in this space or you start getting OutOfMemory exceptions.


I eventually decided that the best course of action was to only work with the tiles, and then have an array that holds the actual information about each tile that I need. Given the number of tiles, it was the only sensible thing I could do.


Like CommanderZ said. Its Windows PRESENTATION Foundation, not Windows Image-manipulation Foundation. You should try to either find some kind of image-manipulation library, but looking at size of your image, then doing everything yourself might be only way.

Especialy, you probably wont be able to work with bitmap as a whole, so you are going to work with tiles. Then it becomes problematic if you need to work with neighboring pixels. But I guess you should look into this yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消