1

I have been at it for a week now, and I give up. How do you extract PNG images embedded in a TStyleBook?

I tried this genuine solution, but am getting a strange result. The bitmap shown in my form at design and runtime is that of a TAniIndicator:

ًRuntime

When I open MultiResBitmap editor of my TImage I see two scaled versions of the same image.

I used this code to save bitmaps:

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to Image1.MultiResBitmap.Count - 1 do
    Image1.MultiResBitmap.Items[i].Bitmap.SaveToFile(IntToStr(i) + '.png');
end;

And I got two scaled images of this:

Extracted image

So, what happened? How come the image shows one thing and saves another? And how can I save all the images so that I can edit them? And more importantly, after editing, how can I put them back into my TStyleBook?

Community
  • 1
  • 1
iMan Biglari
  • 4,674
  • 1
  • 38
  • 83
  • 1
    Why are you not using the Style Editor instead of trying to save/edit/replace them yourself? It's exactly what it's designed to be used to accopmplish. – Ken White Jan 10 '15 at 14:30
  • @KenWhite Bitmap Because Style Editor can only _export_ to `.style` files. It can not _edit_ them, and Firemonkey Style Editor does not even show the `.PNG` files :( – iMan Biglari Jan 10 '15 at 14:58
  • Style Editor is specifically designed to *edit style files* (which explains why it is named *Style Editor*). Why do you need to *export* anything? Use the Style Editor for it's intended purpose. Style Editor can be used to create .style files from scratch so you can design your own styles, which clearly means that the *Editor* part of the name is based on the fact it can **edit**. – Ken White Jan 10 '15 at 15:34
  • @KenWhite For instance, I want to change the background image used by `TToolbar`. The easiest way would be to modify the embedded `.PNG` file. Am I wrong? – iMan Biglari Jan 10 '15 at 15:44

1 Answers1

1

The method described in the SO Q&A you referred to (link here) works ok for me. I can however, also create the error you see by copying too much from the style file. Some style files contain several images and since the image data in the .style file is several pages long, it is easy to paint lines past the end of one image and continue with the next one. When you then copy & paste into your TImage, you see one image and then save an other one. Since this is a c&p error I did not investigate further which image is shown and which saved or why.

For your actual problem, editing an image, use the Bitmap Style Designer. Open a .vsf file or select to create a new one. In the submenu of File - New are several alternatives. After a style is loaded or a new one created, Images in the treeview on the left, lists all embedded images. With the Exportbutton in the center header, you can save all images to a directory of your choice. After editing the images(s) you can use the Update button, alternatively Deleteand Add buttons. Finally save as .vsf or .style file. Of some unexplained reason the BSD can only open .vsf files but can save as both .vsf and .style.


Edit: Based on your comment that you have a modified style in a stylebook and do not want to create a new one, you can save the style in the stylebook into a .style file. From this .style file you can copy the PNG object into a TImage (while looking at form in text mode) and then at runtime save it to a .png file. After editing in an image editor, load it into a TImage (at design time) and copy (in forms text mode) the PNG as a resource back to the .style file. A kind of a hack, but if nothing else ...

Community
  • 1
  • 1
Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • Thanks for your explanation. The reason for this question is, I have a heavily modified style in my `StyleBook`, and now I need to change background of `Toolbar`. I'd rather not create a style from scratch, edit the PNG images, load it into a `StyleBook` and reapply all my modifications. :( – iMan Biglari Jan 12 '15 at 05:43