Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, i want to diplay the size of an image in a picturebox control, a few examples i have found online are using openfile dialog control, but i am not uploading the picture, it is already in the picture box, i have tried this:

C#
Image img = Image.FromFile(openDialog.FileName);
double fileWidth = img.Width;
double fileheigth = img.Height;
double fileByte = (((fileWidth) * (fileheigth))/1024);
label2.Text = "Image Size: " + fileByte.ToString() + " KB";


But it doesn't seem to work, please i will appreciate any assitance. Thanks in advance
Posted
Comments
CPallini 17-Apr-14 6:21am    
What 'size' do you want to know?
Unless there is a file (saving to or loading from the image), there is no file-size (that is it depends on the file format). On the other hand, I doubt it would be useful knowing the in-memory size of the image.
DamithSL 17-Apr-14 6:24am    
what is the application type? how you load or set image of the picturebox ?
Uwakpeter 17-Apr-14 6:32am    
it is a C# windows application, i am loading the image with open file dialog box, and now resized the picture, i have been able to display the original and the resized image on picture boxes, i have also display the original image size, the issue now is to display the resized image size. The format is in Png.
lukeer 17-Apr-14 7:47am    
PNG is a format with lossless compression. You can't exactly tell in advance how large a file it will produce.

Your only chance for an exact value is to save to a file and display the size after that.
Or you settle for a coarse estimate and scale the original file size by pixel count_ratio = newPixelCount/oldPixelCount.
Uwakpeter 17-Apr-14 7:52am    
Thanks Lukeer, the file comes in different formats(jpg,jpeg,gif png), i only reduce the uploaded file size and save in png format, it is png format size that i want to get.

for now i can only compare their different sizes after i have save the resize passport to a folder, i want to display this in the application as well.

this the code that i use to save to a folder:

picBoxResized.Image.Save(@"C:\Users\Default.DEV-PC\documents\picture.png", ImageFormat.Png);

so please how do i display the size after saving to a file here?

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