Jump to content
  • Advertisement
Sign in to follow this  

reading & writing BMP in C#

This topic is 2769 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi friends

I'm using C# (VS 2008), I have to work with extra large images (sometimes bigger than 20000x20000 pixels), I use following commands to tile my images (I should tile these large images into smaller parts - for instance 1000x1000 - so that I can load them in DirectX textures), but windows cannot load some of them (because of extra large size), so I want to read & write BMP files manually, how can I read BMP files pixel by pixel and make smaller BMP files, how I can I write BMP files? can I solve this problem by writing files manually?


Bitmap bmpImage = new Bitmap(fname);//error for big files (perhaps not enough memory?)

any sample or code would be highly appreciated, thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by vcGamer
Bitmap bmpImage = new Bitmap(fname);//error for big files (perhaps not enough memory?)

any sample or code would be highly appreciated, thanks


What is your exact error or exception?

Based on a few quick Google searches of Microsoft forums, it can handle any size image up to your addressable memory limits. A "big" uncompressed bitmap can mean several megabytes, or it could theoretically be multiple gigabytes. There are even examples online that work with 1.6GB images.



If you need to break it apart you can find the format documented in MSDN. It can be a container for many data formats, so check the header for formats that you can't handle.

Share this post


Link to post
Share on other sites
thanks

I mean images that can even be larger than several GBs, as I'm working with geographic files, my problem is lack of enough memory, even if I use 64 bit windows and buy several GBs of RAM, it is always possible that my files are bigger than memory so I cannot load images in the normal way into a C# Bitmap class, and I must read only some pixels of a large BMP file, how can I read only some pixels of my BMP file and write them as a new file?

Share this post


Link to post
Share on other sites
Quote:
Original post by vcGamer
How can I read only some pixels of my BMP file and write them as a new file?

The bmp format is a container. It can have lots of different formats of images inside it.

Check the MSDN link I gave before. It's got the details of each structure.

The file starts with a BITMAPFILEHEADER structure. You'll need to read and parse it.

Next is either a BITMAPINFO or BITMAPCOREINFO structure. These have all the details about how to interpret the rest of the data.

The rest of the file is all based on the contents of those headers. The data can range from an actual bitmap (one bit = one pixel) to 32bpp pixel map. It can be compressed in several different ways, or not. It can use a palette or raw colors. It can have color planes, stride between data, and stride at ends of rows.

You'll need to put all those together to figure out each individual pixel's data.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!