Problems drawing to a 1bpp (indexed) image.

G

Guest

I've been tasked with writing a control for displaying previews from scan software we use. These are scans of plan drawings and are roughly 11000x8000, 1bpp CCITT compressed TIF graphics. I can used Image/Bitmap.FromFile to load them correctly, for display purposes I am creating a scaled render of the original image (so that paints don't have to perform scaling/sampling on every draw) which gets costly enough that we don't want to do it

Problem; I modified the code this morning to use the PixelFormat of the source image in creating this scaled image, now I need to draw the original image to this new image. But Graphics.FromImage() throws an Exception for our TIF images because the target image is an indexed image, and .NET doesn't seem to support this

I found one other post on the newsgroups related to this problem, and Microsoft's solution was to draw to a 24 or 32bpp image and then (for the original author's purposes) save to an indexed format (presumably GIF being that the post dealt with an 8bpp graphic)

That would work great (or well enough) for the original author's problem, but let's do some math

11000*8000=88,000,000 elements/pixel

Not knowing how the Image class was implemented for holding 1bpp graphics, I assume this requires

11,000,000 Bytes, ~10742.2 KB or ~10.4 M

This we could easily accomodate (memory requirements would be low for this image)

According to the post I originally found, the only obvious solution is to create a target graphic that is NOT indexed. Going back to the math this would require

88,000,000*4 Bytes = 352,000,000 B, ~343750 KB or ~ 335.7 M

Obviously we can't do this. It's almost obvious we need a graphics object that can work with an indexed image

My opening pointed out I am drawing to a scaled surface, so my target isn't really 335MB, it's around 30MB (roughly 8% of the physical 'pixel' size of the document). I must display these, but even this allocation is unsatisfactory, especially since my control will allow zooming in to the original document size of 100%, making the scaled image the same size as the source image

Does anyone have any suggestions? Maybe there is a way to scale the image without creating the new image object and drawing it myself? On the same note, can Microsoft drop the $ into the developer time it would take to make a graphics object that could work with indexed/paletted surfaces? This seems like something a fair percentage of developers might need, and if available, would obviously use, so why wouldn't it be done already (except to save time, or meet some design goal/model I may not be aware of)

Thanks in advance for any possible solutions, I'll poke around and look for some solutions and post what I find, we were really hoping to nix the sampling/scaling on every draw (panning code) since it was causing notable lag in the application (being that the original document has a massive resolution on it, even a 2ghz machine with 1gb of RAM takes effort)

- Shau
 
S

Shaun Wilson

LockBits, sounds doable and I figured thats the best I was going to be able
to find, guess I can write my own sampling code to scale the image rather
than rely on any support .NET might have provided. The only downside to this
is the unmanaged code requirement. I just caught up on this thread so I
still have to dig through that url and the LockBits docs and see what I can
do, hopefully I can do something so I don't have to cast to a pointer type.

Thanks for the tip!

- Shaun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top