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
 LayersMergeAll error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

yeohray2

Malaysia
25 Posts

Posted - Dec 21 2020 :  04:33:06  Show Profile  Reply
Similar to this https://www.imageen.com/ieforum/topic.asp?TOPIC_ID=3942, I'm getting the 'Cannot create TIECanvas. Ensure GDI+ is installed.' error or access violations intermittently when creating text layers and trying to flatten them using LayersMergeAll.

I am writing text onto images using threads. Each thread has its own TImageEn instance. Converting and resizing the images don't raise any errors. Creating layers and trying to merge the layers causes errors intermittently. If I restrict the thread pool to only use a single thread, then no error is raised.

Is there some setting that needs to be used when using TImageEn and text layers in threads? The TImageEn instance is created this way:

FWorkImage := TImageEn.Create(nil);
FWorkImage.LegacyBitmap := False;

Thanks in advance.

yeohray2

Malaysia
25 Posts

Posted - Dec 21 2020 :  05:00:20  Show Profile  Reply
The GDI+ error occur in:
TIECanvas.Create

Access violations occur at:
IE_GdipDeleteFont in TIECanvas.DrawTextEx
IE_GdipMeasureString in TIECanvas.DrawTextEx
IE_GdipDeleteStringFormat in TIECanvas.DrawTextEx
IE_GdipDrawString in TIECanvas.DrawTextEx
TIEBitmap.SynchronizeRGBA
TIEBitmap.BuildBitmapScanlines;

If I use a common critical section around each thread's LayersMergeAll call like this:

CriticalSection.Enter;
try
FWorkImage.LayersMergeAll;
WorkImage.Update;
finally
CriticalSection.Leave;
end;

then the access violations occur only in the DrawTextEx function.

Should also add that I'm formatting the text in the layers using RichEdit formatting, so errors are also intermittenly raised in the TIERichEdit unit.
Go to Top of Page

xequte

5965 Posts

Posted - Dec 21 2020 :  15:49:57  Show Profile  Reply
Hi

Have you tried writing directly to the image using TIECanvas text methods, rather than a TIETextLayer?

Are you able to send us a simple demo that reproduce the issue?

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

yeohray2

Malaysia
25 Posts

Posted - Dec 22 2020 :  11:17:56  Show Profile  Reply
Ok, I tried using the TextOut methods, and they do work better, but still occasionally raise the GDI+ error.

I'm attaching a test app, together with the sample image. With layers selected, it's easy to reproduce the error. Deselect the layers option, and it'll use the TextOut methods. It's harder to reproduce the error (might error out the first time, or not at all).

If you can't reproduce the error, try clicking on the Test button repeatedly a few times.

Thanks in advance.

attach/yeohray2/20201222111739_source.zip
149.31 KB
Go to Top of Page

xequte

5965 Posts

Posted - Dec 28 2020 :  18:15:59  Show Profile  Reply
Hi

I can't reproduce an exception when I disable layer usage.

I think you are courting trouble using a TImageEnView object that is shared by all threads. Either create the TImageEnView in the thread execute method, or better yet, don't use a TImageEnView, just a TIEBitmap which you draw using TIECanvas methods.

Ensure you avoid any functions (such as TCanvas ones) that force TIEBitmap to change its location to TBitmap:

https://www.imageen.com/help/TIEBitmap.Location.html

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

yeohray2

Malaysia
25 Posts

Posted - Dec 31 2020 :  04:28:00  Show Profile  Reply
Hi, thanks for taking the time to take a look at this.

What I've done is to use TIEBitmap instead of TImageEn/TImageEnView instances. That seems to cut down the GDI+ errors to very rare occurrences. When that happens, I simply retry the processing again.

Thanks for your help, and wishing you a happy new year.
Go to Top of Page

xequte

5965 Posts

Posted - Jan 01 2021 :  22:32:12  Show Profile  Reply
Thank you. Happy New Year to you too.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To: