Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My bitmap size is 520 KB and i want to convert this size to MB and the size of MB should be  something 9 MB


What I have tried:

I have not tried any. i did not any get code
Posted
Updated 21-Dec-22 20:22pm

To add to what adriancs says, increasing the image resolution or colour depth will not "improve" the image - it may increase the file size, but it can't add information: it can just "stretch" pixels to they cover move space in an image.
The original and new image file format will also have an effect: a BMP file size is very directly related to the image resolution and colour depth because it is not a compressed format, but a JPG, PNG, TIFF, ect. file is compressed and the file size can be very different between what appear to be =very similar images.

Some of the file formats also use "lossy compression" where information is thrown away each time the file is created from an image - so teh file size can shrink (along with the image quality) every time you save it again.

Despite shows like "CSI", you can't look at the reflection in a victims glasses and read the number plate of the car driving past the photographer!

Think about exactly why you want a 9Mb file, rather than how to get it - the chances are you are going down the wrong route right from the beginning.
 
Share this answer
 
You can resize it.

In C#, type the following using statements
C#
using System;
using System.Drawing;
using System.Drawing.Imaging;

Here's the code to resize an image
C#
// Load the image into a Bitmap object
Bitmap image = new Bitmap("image.bmp");

// Here is where u set the enlarged size
int newWidth = 1000;
int newHeight = 1000;

// Create a new Bitmap object with the new dimensions
Bitmap newImage = new Bitmap(newWidth, newHeight);

// Use the Graphics class to resize the image
using (Graphics graphics = Graphics.FromImage(newImage))
{
    graphics.DrawImage(image, 0, 0, newWidth, newHeight);
}

// Save the resized image to a new file
newImage.Save("image-resized.bmp", ImageFormat.Bmp);


**Update

There is another element that affects the size of an bitmap, that is called color depth.

image size = width * height * color depth

The color depth is the number of bits used to represent each pixel color. For example, if the color depth is 24 bits, then each pixel will be represented by 3 bytes (24 bits / 8 bits per byte = 3 bytes).

Assuming a color depth of 24 bits, the size of the image would be:

image size = 4160 * 6240 * 3 = 75,049,600 bytes = 75.05 MB

Note that this is just an approximation, as the actual size of the image may vary depending on the image format and any additional data that is included in the file.

u can use the PixelFormat property of the Bitmap class to specify a higher color depth

example:

C#
// Load the image from a file
Bitmap image = new Bitmap("path/to/image.bmp");

// Set the pixel format to 32 bits per pixel
image.PixelFormat = PixelFormat.Format32bppArgb;

// Save the image to a file with the new pixel format
image.Save("path/to/new_image.bmp", ImageFormat.Bmp);
 
Share this answer
 
v4
Comments
Ridhdhi Vaghani 22-Dec-22 1:31am    
I got the size from this code. But doesn't convert to MB. Please help me.It comes in size KB(600KB) only, I want it in MB(8.5 MB or else 9MB or else 9.5MB (Means more than 8.5MB)).
adriancs 22-Dec-22 1:34am    
increase the size, for example:
int newWidth = 999999;
int newHeight = 999999;
choose the size big enough to surpass 9MB
Ridhdhi Vaghani 22-Dec-22 1:45am    
I want to give a fix height(6240) and width(4160).I want to give a MB(9MB).
adriancs 22-Dec-22 1:56am    
Then you need to adjust the color depth. I have updated my answer above with the info of how to change the color depth.
Ridhdhi Vaghani 22-Dec-22 2:20am    
This is my image:- https://ibb.co/YBcr2Lz
Like this I want the result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900