Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Use 32bit BMP as resource


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 8 - Last Post: Mar 7, 2018 9:47 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Wei Sun

Posts: 8
Registered: 8/14/17
Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2018 8:53 PM
Hello,

I'm using a 32bit BMP as resource in a VCL Windows desktop application with C++ Builder 10.2 in order to do certain pixel manipulation on GRBA channels during run time. The resource file is as followed:

bmp_res RCDATA "a_32bit.bmp"


And while I'm loading the image at run time, it throws exception "Bitmap image is not valid"
std::unique_ptr<TResourceStream> pRes(new TResourceStream(
			reinterpret_cast<NativeUInt>(HInstance),
			L"bmp_res",
			RT_RCDATA));
std::unique_ptr<TBitmap> pBMP(new TBitmap());
pBMP->LoadFromStream(pRes.get()); //throw EInvalidGraphic with message "Bitmap image is not valid"


Is there a special requirement to the format of provided bitmap like version 3.0 when using TBitmap::LoadFromStream?
Mark Richards

Posts: 42
Registered: 12/8/99
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2018 4:12 AM   in response to: Wei Sun in response to: Wei Sun
Wei Sun wrote:
Hello,

I'm using a 32bit BMP as resource in a VCL Windows desktop application with C++ Builder 10.2 in order to do certain pixel manipulation on GRBA channels during run time. The resource file is as followed:

bmp_res RCDATA "a_32bit.bmp"


And while I'm loading the image at run time, it throws exception "Bitmap image is not valid"
std::unique_ptr<TResourceStream> pRes(new TResourceStream(
			reinterpret_cast<NativeUInt>(HInstance),
			L"bmp_res",
			RT_RCDATA));
std::unique_ptr<TBitmap> pBMP(new TBitmap());
pBMP->LoadFromStream(pRes.get()); //throw EInvalidGraphic with message "Bitmap image is not valid"


Is there a special requirement to the format of provided bitmap like version 3.0 when using TBitmap::LoadFromStream?

I just created a 32bit windows bmp file added it to my resources and compiled and run with no issues, but I use a different method to load the resource

std::auto_ptr<Graphics::TBitmap> pBMP(new Graphics::TBitmap());
pBMP->LoadFromResourceName((int)HInstance, "bmp_res");

Have you simply tried LoadFromFile on the original image? This will show if the image file is unreadable straight away

Just drop a TImage on a form, and do something like
Image1->Picture->LoadFromFile("orig filename here.bmp");

Remy Lebeau (Te...


Posts: 9,448
Registered: 12/23/01
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2018 9:28 AM   in response to: Mark Richards in response to: Mark Richards
Mark Richards wrote:

pBMP->LoadFromResourceName((int)HInstance, "bmp_res");

Note that this approach requires the resource type to be BITMAP and not
RCDATA.

--
Remy Lebeau (TeamB)
Wei Sun

Posts: 8
Registered: 8/14/17
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2018 9:56 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Mark Richards wrote:

pBMP->LoadFromResourceName((int)HInstance, "bmp_res");

Note that this approach requires the resource type to be BITMAP and not
RCDATA.

--
Remy Lebeau (TeamB)

Thank you, Remy,

I tried this and it showed a compilation error "bitmap is not in 3.00 format", before I switched the resource type to RCDATA.

This is the reason I asked for format requirement at the end. (My bitmap editor doesn't have an option to select bitmap format.)
Wei Sun

Posts: 8
Registered: 8/14/17
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2018 10:01 AM   in response to: Mark Richards in response to: Mark Richards
Mark Richards wrote:

I just created a 32bit windows bmp file added it to my resources and compiled and run with no issues, but I use a different method to load the resource

thanks, Mark,

What bmp editor did you use to create the file? I used Paint.Net to convert a PNG to 32bit BMP which may create an incompatible format.
Remy Lebeau (Te...


Posts: 9,448
Registered: 12/23/01
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2018 10:38 AM   in response to: Wei Sun in response to: Wei Sun
Wei Sun wrote:

What bmp editor did you use to create the file? I used Paint.Net to
convert a PNG to 32bit BMP which may create an incompatible format.

Are you sure you saved it as an actual BMP file, and not as a PNG file
with a '.bmp' file extension? What do the first few bytes of the file
actually look like? A Windows BMP file begins with 2 bytes 0x42 0x4D.
A PNG file begins with 8 bytes 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A.

--
Remy Lebeau (TeamB)
Wei Sun

Posts: 8
Registered: 8/14/17
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2018 3:01 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Are you sure you saved it as an actual BMP file, and not as a PNG file
with a '.bmp' file extension? What do the first few bytes of the file
actually look like? A Windows BMP file begins with 2 bytes 0x42 0x4D.
A PNG file begins with 8 bytes 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A.

--
Remy Lebeau (TeamB)

It is an actual BMP file. Does c++builder/Delphi have unsupported BMP format? My image editor might fail to setup correct DIB header, or IDE doesn't recognize the header correctly. Neither of these seems possible to me.
Remy Lebeau (Te...


Posts: 9,448
Registered: 12/23/01
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 7, 2018 9:47 AM   in response to: Wei Sun in response to: Wei Sun
Wei Sun wrote:
It is an actual BMP file.

Can you post the actual BMP file to the Attachments forum?

--
Remy Lebeau (TeamB)
Mark Richards

Posts: 42
Registered: 12/8/99
Re: Use 32bit BMP as resource  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 2, 2018 6:21 AM   in response to: Wei Sun in response to: Wei Sun
Wei Sun wrote:
Mark Richards wrote:

I just created a 32bit windows bmp file added it to my resources and compiled and run with no issues, but I use a different method to load the resource

thanks, Mark,

What bmp editor did you use to create the file? I used Paint.Net to convert a PNG to 32bit BMP which may create an incompatible format.

I used GIMP - its free (www.gimp.org)
I simply selected an existing png file, then exported it as a 32bit windows BMP
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02