how to get actual file size from wxImage without saving?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dhana
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Dec 02, 2014 7:25 am

how to get actual file size from wxImage without saving?

Post by dhana » Mon Feb 09, 2015 6:05 am

//I have loaded a bitmap "Sample.bmp" and whose actual/file size is 822 bytes.
wxBitmap bitmap("C:\\Users\\DEPINDSOFT16\\Desktop\\Sample.bmp",wxBITMAP_TYPE_BMP);

wxImage image = bitmap.ConvertToImage();

unsigned char* Data = image.GetData();

size_t DataSize = image.GetWidth()*image.GetHeight()*3;//but the Image DataSize arrived(W*H*3) is 768 bytes.

how can I get the actual size of the image after loading?

DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 223
Joined: Mon Jan 19, 2015 1:45 pm

Re: how to get actual file size from wxImage without saving?

Post by DenDev » Mon Feb 09, 2015 12:59 pm

The image.GetData() function only return raw pixel data without the file header (BITMAPINFOHEADER) that describes the image (bits pr. pixel, width, height and so on).

This should give you the (file) size of the image including header (or -1 if operation fails):

Code: Select all

long GetImageSize(wxImage &image)
{
wxMemoryOutputStream temp;
return image.SaveFile(temp, wxBITMAP_TYPE_BMP) ? temp.TellO() : -1;
}
I have a bad habbit of not testing the code I post :D

dhana
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Dec 02, 2014 7:25 am

Re: how to get actual file size from wxImage without saving?

Post by dhana » Wed Feb 11, 2015 11:18 am

Thanks for reply..

Post Reply