Jump to content

  • Log In with Google      Sign In   
  • Create Account


Reducing Bitmap Object size


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Tdawg30   Members   -  Reputation: 172

Like
0Likes
Like

Posted 14 May 2012 - 11:06 PM

Hey, just wondering is there anyway of reducing the size of a bitmap object(space on the disk, not dimensions) before I save it to disk? I have a program which is accepting images as input, changing the RGB values of the image, and then outputting the new image, the problem is the outputted image always takes up more memory than the original image even though if I am not adjusting its dimensions in anyway.

Google searches typically turn up information regarding dimensions and not disk space. Any information on handling images in a different fashion or reducing the space of a bitmap object would be appreciated.

Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 8178

Like
0Likes
Like

Posted 15 May 2012 - 12:10 AM

You are probably changing the bitmap's color depth (e.g. reading it as a RGB image (96 bits per pixel) and writing it back as a RGBA image (128 bits per pixel)). Did you check that? This is my best guess.

As for reducing file size in general, bitmaps are often highly compressible. You could compress the file before saving it to disk and decompress it before reading it. Bitmap doesn't offer much support in this direction, so you may have to use an external library to perform the compression. Or you could use PNG's instead which natively support compression.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 Tdawg30   Members   -  Reputation: 172

Like
0Likes
Like

Posted 15 May 2012 - 12:41 AM

Thanks for the reply Bacterius,

How would I check if I am writing it back as an RGBA image? I am creating new pixel colors using the Color.FromArgb() method, and saving the image using the Bitmap Class' save() method

#4 Bacterius   Crossbones+   -  Reputation: 8178

Like
1Likes
Like

Posted 15 May 2012 - 12:48 AM

Just check the bitmap's type in the file's properties (or check the file size - if the file size changes according to a 3:4 ratio it's almost certain this is what's happening). As for saving in the correct format, you want to change the bitmap's pixelformat before saving it (I assume - I've never used the BItmap class in C# but the terminology is standard across most languages):

http://msdn.microsoft.com/en-us/library/system.drawing.image.pixelformat.aspx

So for a 24-bit RGB image you will want the PixelFormat.Format24bppRgb one probably. My guess is the bitmap reverted to RGBA format as you wanted to set alpha channels (otherwise it shouldn't have changed).

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 Tdawg30   Members   -  Reputation: 172

Like
1Likes
Like

Posted 15 May 2012 - 01:13 AM

You are right, the original image that was read came in the format of 24bppRgb, however the one being outputted is 32bppArgb. The problem is the original image is actually being read from a pdf file of the size ~110 kb, and the bitmap object that is being outputted is around 2mb!! obviously the problem isn't limited to the pixel format, however this a start in the right direction.

Thank you for your help.

#6 Bacterius   Crossbones+   -  Reputation: 8178

Like
0Likes
Like

Posted 15 May 2012 - 01:24 AM

The bitmap could be compressed, which would explain the huge size difference. The bitmap "specification" does allow for compression to take place (there's a field for it in the header but I've personally never seen it used). Perhaps the Bitmap class provides a wrapper or some sort of interface to do the same thing, but I wouldn't know that much :)

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#7 BeerNutts   Crossbones+   -  Reputation: 2570

Like
0Likes
Like

Posted 15 May 2012 - 09:24 AM

The pdf is obviously compressed. When you read the bmp off the PDF, you read it uncompressed, and then save it as such. In general, a RAW BMP, even using 24 bpp, will be width*height*3 bytes large. Using that, you will find the minimum size you will be output using 24bpp with no compression.

If you want compression, there's 2 options: #1, using BMP's built in compression technique, which is Run Length Encoding (RLE), and not the best (google it if you want). Or,
#2, use an external library to compress the image into another format (PNG, for example), and save that.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#8 bobbias   Members   -  Reputation: 120

Like
0Likes
Like

Posted 15 May 2012 - 09:50 AM

There's also the option of using his own compression on a normal BMP file. Huffman coding would likely provide decent compression compared to RLE, and is not terribly difficult to program.

#9 BeerNutts   Crossbones+   -  Reputation: 2570

Like
0Likes
Like

Posted 15 May 2012 - 11:33 AM

There's also the option of using his own compression on a normal BMP file. Huffman coding would likely provide decent compression compared to RLE, and is not terribly difficult to program.


But then it wouldn't be a BMP, it would be his own format. And he would need a special program to open it. I'm assuming he wants to keep it within the bounds of a popular image standard, thus, RLE in a BMP (which is supported in the BMP header), or using PNG (or some other format if he chooses)

Edited by BeerNutts, 15 May 2012 - 11:34 AM.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS