Board index » delphi » how to set palette into a resource file bitmap

how to set palette into a resource file bitmap


2005-07-17 10:27:44 PM
delphi196
Hello,
I have a 256 bmp with a optimized palette. Since the palette is optimized
the bmp displays very nicely. Now I want to save into a delphi resource file
this bmp. If i open the delphi image editor and create new bmp with 256
color and then i copy and paste from the saved version of my bmp, the
resulting palette is not optimized anymore, in other words copying and
pasting doesnt copy also the palette.
So now the resource bmp looks very ugly.
How can i solve this problem, maybe there is another tool to save a bmp into
resource file, besides the standard delphi image editor?
 
 

Re:how to set palette into a resource file bitmap

"Francesco Savastano" <XXXX@XXXXX.COM>
skrev i en meddelelse news:42da6ad8$XXXX@XXXXX.COM...
Quote
How can i solve this problem, maybe there is another tool to save a bmp
into
resource file, besides the standard delphi image editor?
Use notepad.
Create a text file containing a like this:
PALBMP RCDATA "filename.bmp"
Save this files with a *.RC extension.
If you have Delphi 5 + add the .RC file to the project and build it.
If you have Delphi 4 - you have to compile the .RC file manually using the
resource compiler and include the resulting .RES file in the project.
--
Finn Tolderlund
 

Re:how to set palette into a resource file bitmap

Hello,
actually I have already a .res file that contains also other resources. So
it's already compiled. I am using Delphi 5.
The resource file is to be used in a component not in a project, maybe you
can advice better on what to do?
I dont want to have too many resource files, I'd prefer everything is
enclosed into one res file.
Thanx,
Francesco
--
New World Software
Creative Tools for Creative People
new-world-software.com
"Finn Tolderlund" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote

"Francesco Savastano" <XXXX@XXXXX.COM>
skrev i en meddelelse news:42da6ad8$XXXX@XXXXX.COM...
>How can i solve this problem, maybe there is another tool to save a bmp
into
>resource file, besides the standard delphi image editor?

Use notepad.
Create a text file containing a like this:
PALBMP RCDATA "filename.bmp"

Save this files with a *.RC extension.
If you have Delphi 5 + add the .RC file to the project and build it.
If you have Delphi 4 - you have to compile the .RC file manually using the
resource compiler and include the resulting .RES file in the project.
--
Finn Tolderlund


 

Re:how to set palette into a resource file bitmap

Quote
actually I have already a .res file that contains also other resources. So
it's already compiled. I am using Delphi 5.
The resource file is to be used in a component not in a project, maybe you
can advice better on what to do?
I dont want to have too many resource files, I'd prefer everything is
enclosed into one res file.
But that doesn't really matter. I mean the resulting exe files does not
differ, no matter how many .res files you include. I usually have one
.res file per component (or at least one per package), and one for the
project itself (in addition to the one created automatically).
Jens
 

Re:how to set palette into a resource file bitmap

Jens I meant I dont want to have more than 1 resource file for the
component. I want to use the one I have and add to it this bmp. Since Finn
adviced to create a rc file containing just the bitmap, i wondered instead
if there is a way to do this using the already existing resource file?
"Jens Gruschel" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
>actually I have already a .res file that contains also other resources.
>So it is already compiled. I am using Delphi 5.
>The resource file is to be used in a component not in a project, maybe
>you can advice better on what to do?
>I dont want to have too many resource files, I'd prefer everything is
>enclosed into one res file.

But that doesn't really matter. I mean the resulting exe files does not
differ, no matter how many .res files you include. I usually have one .res
file per component (or at least one per package), and one for the project
itself (in addition to the one created automatically).

Jens
 

Re:how to set palette into a resource file bitmap

Quote
Jens I meant I dont want to have more than 1 resource file for the
component. I want to use the one I have and add to it this bmp. Since Finn
adviced to create a rc file containing just the bitmap, i wondered instead
if there is a way to do this using the already existing resource file?
Maybe that is possible with another resource editor. But I prefer not to
create res files with an editor at all. Why don't you put all bitmaps
and other data into a .rc file? it is much more flexible.
Jens
 

Re:how to set palette into a resource file bitmap

"Francesco Savastano" <XXXX@XXXXX.COM>
skrev i en meddelelse news:42da9fd2$XXXX@XXXXX.COM...
Quote
Jens I meant I dont want to have more than 1 resource file for the
component. I want to use the one I have and add to it this bmp. Since Finn
adviced to create a rc file containing just the bitmap, i wondered instead
if there is a way to do this using the already existing resource file?
You write one line in the .RC file for each bitmap you want to include.
--
Finn Tolderlund
 

Re:how to set palette into a resource file bitmap

Quote
Maybe that is possible with another resource editor. But I prefer not to
create res files with an editor at all. Why don't you put all bitmaps and
other data into a .rc file? it is much more flexible.

Jens
I even never considered this option till now:) maybe you're right, i always
used image editor to do this stuff, but obviously Borland didnt put any
further development in it (for example tru color bitmaps are not supported).
Do you have some example of home made rc files just to make sure that i will
do everything right with oyur approuch?
 

Re:how to set palette into a resource file bitmap

Quote
Do you have some example of home made rc files just to make sure that i will
do everything right with oyur approuch?
Here is the content of the .rc file I use for my PStart application:
LOGOBITMAP BITMAP Logo400.bmp
TRAYICON00 ICON TrayDefault.ico
TRAYICON01 ICON TrayOutline.ico
TRAYICON02 ICON TrayP.ico
TRAYICON03 ICON TrayS.ico
Really simple. You can also find many articles about resource files
including better examples than mine.
Jens
P.S. I added "Compile with BRCC32" to the context menu for .rc files to
compile them easily, but as Finn already said, depending on the Delphi
version you are using, you don't even have to do this manually.
 

Re:how to set palette into a resource file bitmap

Hi
You can try Resource Builder from SIComponents.com ... its a great resource
editor for including even 24 bit bitmap resources.
BEst Regards
"Francesco Savastano" <XXXX@XXXXX.COM>
writes news:42da6ad8$XXXX@XXXXX.COM...
Quote

Hello,
I have a 256 bmp with a optimized palette. Since the palette is optimized
the bmp displays very nicely. Now I want to save into a delphi resource
file
this bmp. If i open the delphi image editor and create new bmp with 256
color and then i copy and paste from the saved version of my bmp, the
resulting palette is not optimized anymore, in other words copying and
pasting doesnt copy also the palette.
So now the resource bmp looks very ugly.
How can i solve this problem, maybe there is another tool to save a bmp
into
resource file, besides the standard delphi image editor?


 

Re:how to set palette into a resource file bitmap

I tried to use this program but it didnt work well for me: I have put a
24bit bmp into my resourse file, then in my component I load this bitmap
into an imageList:
ImageList_Rotatebuttons.ResInstLoad( HInstance, rtBitmap, 'ROTATEBTNS1',
clFuchsia );
then I take various small bmps from the imagelist in this way:
tmpbmp := tbitmap.create;
tmpbmp.PixelFormat := pf24bit;
try
ImageList_Rotatebuttons.GetBitmap(3+i,tmpbmp)
tmpbmp.PixelFormat := pf24bit;
// then i display the bitmap on my component canvas
fDrawingBmp.Canvas.draw(xb,yb,tmpbmp);
finally
tmpbmp.free;
end;
The problem is that the bitmaps don't display correctly: they have wrong
colors and lost many details.
Maybe i do something wrong in my code, or it is just the Resource Builder
program doesnt work well?
--
New World Software
Creative Tools for Creative People
new-world-software.com
"Mr. X" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
Hi
You can try Resource Builder from SIComponents.com ... its a great
resource
editor for including even 24 bit bitmap resources.
BEst Regards

"Francesco Savastano" <XXXX@XXXXX.COM>
writes news:42da6ad8$XXXX@XXXXX.COM...
>
>Hello,
>I have a 256 bmp with a optimized palette. Since the palette is optimized
>the bmp displays very nicely. Now I want to save into a delphi resource
file
>this bmp. If i open the delphi image editor and create new bmp with 256
>color and then i copy and paste from the saved version of my bmp, the
>resulting palette is not optimized anymore, in other words copying and
>pasting doesnt copy also the palette.
>So now the resource bmp looks very ugly.
>How can i solve this problem, maybe there is another tool to save a bmp
into
>resource file, besides the standard delphi image editor?
>
>


 

Re:how to set palette into a resource file bitmap

I did it as you said but the bitmaps displayed have wrong colors:
Maybe I am doing something wrong in my code? In my component the resource
bitmap is retrieved into an ImageList and then the various bmps inside the
imagelist are drawn on my component's canvas:
ImageList_Rotatebuttons.ResInstLoad( HInstance, rtBitmap, 'ROTATEBTNS1',
clFuchsia );
then I take various small bmps from the imagelist in this way:
tmpbmp := tbitmap.create;
tmpbmp.PixelFormat := pf24bit;
try
ImageList_Rotatebuttons.GetBitmap(i,tmpbmp)
tmpbmp.PixelFormat := pf24bit;
// then i display the bitmap on my component canvas
fDrawingBmp.Canvas.draw(xb,yb,tmpbmp);
finally
tmpbmp.free;
end;
The problem is that the bitmaps don't display correctly: they have wrong
colors and lost many details.
Maybe i do something wrong in my code?
I have like the feeling that something in the imagelist messes up the
colors..
Thanx in advance for your answers,
Francesco.
"Jens Gruschel" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
>Do you have some example of home made rc files just to make sure that i
>will do everything right with oyur approuch?

Here is the content of the .rc file I use for my PStart application:

LOGOBITMAP BITMAP Logo400.bmp
TRAYICON00 ICON TrayDefault.ico
TRAYICON01 ICON TrayOutline.ico
TRAYICON02 ICON TrayP.ico
TRAYICON03 ICON TrayS.ico

Really simple. You can also find many articles about resource files
including better examples than mine.

Jens

P.S. I added "Compile with BRCC32" to the context menu for .rc files to
compile them easily, but as Finn already said, depending on the Delphi
version you are using, you don't even have to do this manually.
 

Re:how to set palette into a resource file bitmap

Quote
I have like the feeling that something in the imagelist messes up the
colors..
Probably it is the imagelist. There are some conversions involved from
one pixel format to another. Do you need the image list at all? I think
you can do it more directly. Create a TBitmap instead, and load your
bitmap from the resource. Now draw the part you want to with BitBlt.
Something like:
BitBlt(fDrawingBmp.Canvas.Handle, xb, yb, GlyphWidth, GlyphHeight,
BitmapFromRes.Canvas.Handle, I * GlyphWidth, 0);
Jens
 

Re:how to set palette into a resource file bitmap

Thx for the hint Jens, infact I removed the imagelist and used a plain
TBitmap to read the strip from the resource files. Now everything works ok..
Francesco
"Jens Gruschel" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
>I have like the feeling that something in the imagelist messes up the
>colors..

Probably it is the imagelist. There are some conversions involved from one
pixel format to another. Do you need the image list at all? I think you
can do it more directly. Create a TBitmap instead, and load your bitmap
from the resource. Now draw the part you want to with BitBlt. Something
like:

BitBlt(fDrawingBmp.Canvas.Handle, xb, yb, GlyphWidth, GlyphHeight,
BitmapFromRes.Canvas.Handle, I * GlyphWidth, 0);

Jens
 

Re:how to set palette into a resource file bitmap

Hello,
Resource Builder doesn't make any conversions or modifications to original
bitmaps while compiling them to RES. As well as it supports bitmaps with
custom palettes.
The data loss could occur while loading image to the image list. Try to
create manually your image list with the following code:
ImageList_Rotatebuttons.Handle := ImageList_Create(32, 32, ILC_COLOR24, 4,
4); // 32, 32 means 32x32 pictures in image list
Please let us know if this helps.
"Francesco Savastano" <XXXX@XXXXX.COM>
writes news:XXXX@XXXXX.COM...
Quote
I tried to use this program but it didnt work well for me: I have put a
24bit bmp into my resourse file, then in my component I load this bitmap
into an imageList:

ImageList_Rotatebuttons.ResInstLoad( HInstance, rtBitmap,
'ROTATEBTNS1',
clFuchsia );

then I take various small bmps from the imagelist in this way:

tmpbmp := tbitmap.create;
tmpbmp.PixelFormat := pf24bit;
try

ImageList_Rotatebuttons.GetBitmap(3+i,tmpbmp)
tmpbmp.PixelFormat := pf24bit;

// then i display the bitmap on my component canvas
fDrawingBmp.Canvas.draw(xb,yb,tmpbmp);

finally
tmpbmp.free;
end;

The problem is that the bitmaps don't display correctly: they have wrong
colors and lost many details.
Maybe i do something wrong in my code, or it is just the Resource Builder
program doesnt work well?

--
New World Software
Creative Tools for Creative People
new-world-software.com
"Mr. X" <XXXX@XXXXX.COM>ha scritto nel messaggio
news:XXXX@XXXXX.COM...
>Hi
>You can try Resource Builder from SIComponents.com ... its a great
>resource
>editor for including even 24 bit bitmap resources.
>BEst Regards
>
>"Francesco Savastano"
<XXXX@XXXXX.COM>
>writes news:42da6ad8$XXXX@XXXXX.COM...
>>
>>Hello,
>>I have a 256 bmp with a optimized palette. Since the palette is
optimized
>>the bmp displays very nicely. Now I want to save into a delphi resource
>file
>>this bmp. If i open the delphi image editor and create new bmp with 256
>>color and then i copy and paste from the saved version of my bmp, the
>>resulting palette is not optimized anymore, in other words copying and
>>pasting doesnt copy also the palette.
>>So now the resource bmp looks very ugly.
>>How can i solve this problem, maybe there is another tool to save a bmp
>into
>>resource file, besides the standard delphi image editor?
>>
>>
>
>