#1 2019-07-05 11:48:56

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Draw and scale EMF to TImage.Canvas does not show text

Hello,

I'm using Delphi 6 and I try to draw EMF-Files on a TImage.Canvas. I use the newest SynGdiPlus.pas. I just added the Unit to the uses-part.

I try the following code:


var 
   MF: TMetaFile;
   Rect1: TRect;
begin
   Gdip := TGDIPlusFull.Create;
   MF := TMetaFile.Create;

   MF.LoadFromFile('Test_Synopse.emf');

   Rect1.Left := 0;
   Rect1.Top := 0;
   Rect1.Right := Image2.Width;
   Rect1.Bottom := Image2.Height;

   Gdip.DrawAntiAliased(MF, Image2.Canvas.Handle, Rect1);   

   MF.Free;
   Gdip.Free;
end;


Most files work fine with this code. Some Files are shown just with the Lines included but not with the Text included.

Here one of the problem-files could be downloaded:
http://www.mediafire.com/file/f64b3f84k … e.EMF/file

If this file is drawn on the Image2.Canvas with the code above you can not see any text.
Somebody knows what I am doing wrong?

My second question:
The last line in my code above (Gdip.Free) results in an exception. Somebody knows why?

Thanks
Don

Offline

#2 2019-07-05 12:25:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,494
Website

Re: Draw and scale EMF to TImage.Canvas does not show text

Gdip is global, and shouldn't be instantiated locally.

I will look into the EMF but it sounds like a resolution problem...

Offline

#3 2019-07-17 10:18:04

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Draw and scale EMF to TImage.Canvas does not show text

Thanks for your answer.
Here some more information about my tests:

I'm testing on 32-Bit-Windows-XP (I have to...) and on 64-Bit-Windows-7

On my 32-Bit-Windows-XP-PC I get several error-messages testing different emf-files:
- with some emf-Files the text is not shown  (see my first post and the link to the example-file which can be downloaded from mediafire)
- some emf-files the graphic is not shown collectly
- some emf-files result in an divide by zero error and nothing is shown

On my 64-Bit-Windows-7-PC there is just one Problem:
- with some emf-Files the text is not shown (see my first post and the link to the example-file which can be downloaded from mediafire)

The same emf-files which causes the problems on the XP-PC are shown correctly on the Win7-PC.
So I think the reason is a newer GDIPLUS.DLL.

But all files which causes problems with the code from my first post from SynGdiPlus are shown correctly and with very good quality
if I open them with windows-paint, windows-picture and fax viewer, EMFExplorer or IrfanView! Even on my XP-PC!
And I think all these tools also use GDI. So the GDIPLUS.DLL on my XP-PC should be ok.

It's all a little bit frustrating...

@ab: did you have some time to test my emf-file?

Offline

#4 2019-07-23 10:06:46

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Draw and scale EMF to TImage.Canvas does not show text

Hi to all.

I tested some other options to solve the problems:


1. Windows-GDI-functions "SetStretchBltMode" and "StretchBlt"
2. GDI+ API by http://www.progdigy.com
3. Resample with GraphicEx-Unit by Mike Lischke


To use these 3 options the EMF-Files must be converted to Bitmaps first.
The converted Bitmaps can be scaled in a very good quality with all 3 options!

Unfortunately the conversion from EMF to Bitmap lasts up to one second, depending
on the size and content of the source-EMF-Files.
(In my tests the source-EMF-Files must be converted in original size to keep the quality.)
After the conversion the scaling-process of option 1. and 2. is very fast.

The scaling/resampling-process of option 3. with GraphicEx lasts sometimes
up do 2 seconds for each Bitmap.

So the good thing of all 3 options is, that every EMF-File can be scaled in a
very good quality. I get no problems or error-messages. All files I tested work
fine. And all works fine on all Windows-Systems (Windows XP, Windows 7, Windows 10).

But the disadvantage is, that this 3 options take to much time for processing.

Using SynGdiPlus I can scale the EMF-Files directly (no need to convert to Bitmap)
and the scaling-process is very fast und result in a very good quality.
So I would prefer to use SynGdiPlus.
But unfortunately I get all the described problems and errors.


Somebody out there with any ideas to this?

Offline

Board footer

Powered by FluxBB