ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 SVG to BMP?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

913 Posts

Posted - Aug 19 2024 :  15:07:18  Show Profile  Reply
I need to create 32-bit BITMAP Thumbnail images from SVG files (preserving transparency) quickly and efficiently, with a customizable size.

Is this possible with ImageEn?

xequte

38457 Posts

Posted - Aug 19 2024 :  17:46:33  Show Profile  Reply
Hi Peter

Yes, you can Native, Skia (Delphi 12) or ImageMagick for SVG loading. See:

https://www.imageen.com/help/File_Formats.html#SVG

To save as a 32bit Bitmap, see the example at:

http://www.imageen.com/help/TIEBitmap.SynchronizeRGBA.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

913 Posts

Posted - Aug 20 2024 :  00:53:26  Show Profile  Reply
Hi Nigel

I've tried the SVGParsing demo:

\Demos\InputOutput\SVGParsing\SVGParsing.dpr

Unfortunately, it does not work with the attached SVG image:

attach/PeterPanino/202482005034_Salzburg - Herbststimmung.zip
1013.23 KB

Nor does it with this small SVG image:

attach/PeterPanino/20248201138_directions-arrows-8-blue.zip
1.29 KB

It does work, however, if I add Vcl.Skia to the uses clause. Maybe you should include Vcl.Skia in your demo by using a conditional compiler directive:

uses
  {$IF CompilerVersion >= 36.0}  // Delphi 12 corresponds to version 36.0
  Vcl.Skia,
  {$ENDIF}
  System.SysUtils, Vcl.Forms, ...;  // other units
Go to Top of Page

PeterPanino

913 Posts

Posted - Aug 20 2024 :  03:35:20  Show Profile  Reply
I've done some tests by trying to get a valid TBitmap out from TImageEnIO:

CodeSite.Send('ASVGFilePath', ASVGFilePath); // this shows the correct SVG file path
var ThisImageEnIO := TImageEnIO.Create(nil);
try
  try
    ThisImageEnIO.ImportFromFileSVG(ASVGFilePath, AWidth, AHeight, True);
    ThisImageEnIO.IEBitmap.Write('test.bmp'); 
    CodeSite.Send('ThisImageEnIO.IEBitmap.VclBitmap:', ThisImageEnIO.IEBitmap.VclBitmap); // This outputs a BLACK BITMAP!
    ThisImageEnIO.Bitmap.SaveToFile('test.bmp'); // this is not executed
    CodeSite.Send('ThisImageEnIO.Bitmap:', ThisImageEnIO.Bitmap); // this is not executed
  except
    CodeSite.Send('Exception'); // this is not executed
  end;
finally
  ThisImageEnIO.Free;
end;


This workaround seems to work, but randomly, the same SVG file does not:

ThisImageEnIO.ImportFromFileSVG(ASVGPath, AWidth, AHeight, True);
var bmp := TBitmap.Create;
try
  ThisImageEnIO.IEBitmap.CopyToTBitmap(bmp); // randomly creates a BLACK square with the same SVG file that worked previously
  CodeSite.Send('bmp', bmp); 
finally
  bmp.Free;
end;


So, how can I create a valid TBitmap in memory from TImageEnIO?
Go to Top of Page

xequte

38457 Posts

Posted - Aug 20 2024 :  22:07:58  Show Profile  Reply
Hi Peter

Implementation of our native SVG support is ongoing:

http://www.imageen.com/help/SVG_Implementation_Status.html

But both the files you posted are supported in the current beta (email us).

Skia will generally give a better result, but is only supported in Delphi 12 and requires a large DLL.

It is not enough to add Vcl.Skia to your uses at run-time, it also needs to be enabled in the project (which copies the necessary the DLL, among other things).


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38457 Posts

Posted - Aug 20 2024 :  22:12:01  Show Profile  Reply
Accessing TIEBitmap.VclBitmap changes the bitmap location to TBitmap (so your debugging code will actually change the operation of ImageEn (making it more prone to memory errors). Instead call TIEBitmap.AssignTo() to output to a temporary bitmap and send that to CodeSite.

Alternatively (and off the record) you can use:

CodeSite.Send('ThisImageEnIO.IEBitmap:', ThisImageEnIO.IEBitmap.GetTempTBitmapEx() );


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38457 Posts

Posted - Aug 20 2024 :  22:17:25  Show Profile  Reply
These both work fine for me:

  bmp1 := TIEBitmap.Create();
  bmp1.LoadFromFile( 'D:\Salzburg - Herbststimmung.svg' );
  bmp1.SaveToFile( 'D:\Salzburg - Herbststimmung.bmp' );
  bmp1.Free;


  io := TImageEnIO.Create(nil);
  try
    io.ImportFromFileSVG( 'D:\Salzburg - Herbststimmung.svg', AWidth, AHeight, True);
    io.SaveToFile('D:\Salzburg - Herbststimmung2.bmp');
  finally
    io.Free;
  end;



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

913 Posts

Posted - Aug 21 2024 :  02:10:27  Show Profile  Reply
This has created so far the best results:


var
  iebmp: TIEBitmap;
begin
  iebmp := TIEBitmap.Create;
  iebmp.LoadFromFile(ASVGFile);
  iebmp.CopyToTBitmap(Bitmap, True);


But the resulting Bitmap size is too small and randomly creates just a black square.
Go to Top of Page

xequte

38457 Posts

Posted - Aug 21 2024 :  05:21:12  Show Profile  Reply
Hi

Please provide a sample image that creates a black square.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

913 Posts

Posted - Aug 21 2024 :  12:12:24  Show Profile  Reply
Hi Nigel,

I have now solved the problem using the Skia capabilities in Delphi 12. I will publish a blog article and then post a link here.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: