Large image

  • Thread starter Thread starter Broeden
  • Start date Start date
B

Broeden

Hi,

I have a map in the format of 3000 * 3000 pixel bmp-file. This is of
course to big to load into a bitmap.
Does anyone have any ideas how to handle this image to be able to pan
the map in the PDA. Do I have to cut the image into smaller pieces or
is it somehow possible to read small parts of the image depending on
which part of the map to be shown while panning?

/Broeden
..
 
The easiest way would be to use a PictureBox control and set the scroll bars
which will allow you to scroll the image. This depends on the size of the
image (colour depth) as to whether your device will render it before it runs
out of memory.

If size (depth) is a problem, maybe divide the image up and draw "tiles"
when required.
 
If size (depth) is a problem, maybe divide the image up and draw "tiles"
when required.

Yes, the size is the problem. I have thought about dividing the image
into smaller images. But if it's possible I want to read parts of
image directly from the imagefile or load the whole image into a byte
array and than create selected parts of the image when needed. Is this
possible?

Is it possible to read parts of the image (bmp) via some sort of
stream?

/Broeden
 
To do it directly is difficult becasue you have to look at the stride of the
data and pull only parts of each scan line, essentially pulling just the
data you want and assembling a new bitmap. Doable, but not fun. It's a lot
easier to use an existing function like that which the native Imaging
library provides. The CF doesn't directly have any wrappers for this stuff,
but we'd done it in the SDF:

http://blog.opennetcf.org/afeinman/CategoryView,category,SDF 2.0.aspx
 
Nothing. The community edition is free, so just download, install, add a
reference and use. If you want Studio integration with toolbox support,
help, templates and full source code then you can buy the SDF Extensions for
Studio for a nominal fee.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
Nothing.  The community edition is free, so just download, install, add a
reference and use.  If you want Studio integration with toolbox support,
help, templates and full source code then you can buy the SDF Extensions for
Studio for a nominal fee.

Thanks again!

I have install the SDF and tested the samples. I have found out how to
load parts of the image to get a thumbnail of the image.
But is it possible to load for instance the upper left 1000*1000
pixels of a large image?

/Broeden
 
If I recall, you're working with BMP images. If that is the case, you can
write a relatively simply method to read and decode the BMP into a Bitmap
object. use SetPixel while testnig and LockBits to optimize.

Hilton


Nothing. The community edition is free, so just download, install, add a
reference and use. If you want Studio integration with toolbox support,
help, templates and full source code then you can buy the SDF Extensions
for
Studio for a nominal fee.

Thanks again!

I have install the SDF and tested the samples. I have found out how to
load parts of the image to get a thumbnail of the image.
But is it possible to load for instance the upper left 1000*1000
pixels of a large image?

/Broeden
 
The problem there is just trying to load a 3000x3000 bitmap is very likely
to run the device out of memory long before it's fully in memory. SetPixel
will be painfully slow if attempting to copy the data. It's probably better
to just lock the destination bitmap and use copy methods to pull from a
stream and write it into the scan0 ptr at an offset.


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
 
This is a little new to me.

Can you be a bit more specific? For instance, to simplify. How do I
read half of a 2000 *2000 pixel bmp (2000 * 1000) into an bitmap
object?
Without first loading the whole image into the memory of course.

/Broeden
 
Chris,
The problem there is just trying to load a 3000x3000 bitmap is very likely
to run the device out of memory long before it's fully in memory.

Correct, that's why I said that he should write a "read and decode" method,
essentially the equivalent of "new Bitmap (filename, x, y, cx, cy)".
SetPixel will be painfully slow if attempting to copy the data. It's
probably better to just lock the destination bitmap and use copy methods
to pull from a stream and write it into the scan0 ptr at an offset.

Right, that's why I suggested to use SetPixel while testing (i.e. just get
it working), then use LockBits (i.e. scan0) to optimize, unless using scan0
initially would be best although i doubt it given the number of BMP formats,
pixel depths, etc.

Hilton
 
Well, you'll have to browse the web or buy a book and become familiar with
the BMP format - it's a pretty brain dead format - hence its bad compression
and then figure out what parts to read and 'decode' into bits, bytes, and
pixels. The bottom line it that you are going to have to write the image
reading code or buy it if anyone has something. If I have some time, I
might be able to write it for you, but not before the end of April.

Hilton
 
Thanks Hilton for your reply!

I found some articles on how to manipulate bitmaps on the Net to start
with.

What I'm now looking for is an example of how to select parts of the
stream.

For instance how could SkipEverySecondPixel be implemented?

Stream stream = new Stream("test.bmp");
Stream newStream = SkipEverySecondPixel(Stream);
bmp = new Bitmap(NewStream );
stream.Close();
newStream.Close();

/Broeden
 
You have to use Seek on the source stream and manually calculate the offsets
based on the image properties (bits per pixel, stride, etc).
 
If the BMP is compressed, you need to handle that too. Do this using
streams; i.e. open the BMPStream using another stream (or filename). This
BMPStream would have calls like "Color NextPixel", SkipPixels (int n), and
"MoveToNextRow" etc; i.e. the code reading this stream should not care about
how the BMP is compressed. If it made sense, you could add SkipRow(), you
don't need SkipPixel since you could just call NextPixel and ignore what it
returns. However, getting back to what you originally asked, you need to
think about the new Bitmap (filename, x, y, cx, cy) call. If you can solve
that, you're pretty much done.

Hope that makes sense.

Hilton
 
Back
Top