The MindFusion Forums
Flow Diagramming Components >> WPF >> Reset ZoomFactor in CreateImage
https://mindfusion.eu/Forum/YaBB.pl?num=1505198994

Message started by vremennyi on Sep 12th, 2017 at 6:49am

Title: Reset ZoomFactor in CreateImage
Post by vremennyi on Sep 12th, 2017 at 6:49am
I need to export diagram image at 100% size.
Diagram.CreateImage uses ZoomFactor from DiagramView and resizes all layers in diagram in the exported image.
Reset ZoomFactor to 100 before exporting works only on small diagrams that fit in the View. Large diagrams are blurred during export.
Is there a way to get a clear diagram image in 100% size?
In addition it would be great if there is the way to export any Rect to image, i.e. Diagram.GetContentBounds() in default.

Added export button to Demo project


Code (html):
      
<Menu Height="22" Margin="0,0,0,0" Name="mainMenu" VerticalAlignment="Top" HorizontalAlignment="Stretch">
  <MenuItem Name="mFile" Header="_File">
  ...
    <MenuItem Name="mPrintPreview" Header="Print Pre_view..." Click="mPreview_Click" />
    <MenuItem Name="mExportToImage" Header="Export to image..." Click="mExportToImage_Click" />
  ...
  </MenuItem>



Code (c++):

private void mExportToImage_Click(object sender, RoutedEventArgs e)
{
  diagram.ZoomFactor = 100.0;
  var image = diagram.CreateImage();
  var tempFileName = "D:\\Temp\\123.png";
  Utilities.SaveImage(image, tempFileName);
  Process.Start(tempFileName);
}


123.png ( 145 KB | 100 Downloads )

Title: Re: Reset ZoomFactor in CreateImage
Post by vremennyi on Sep 12th, 2017 at 7:04am
Without reseting ZoomFactor to 100% just getting transparent borders.
2017-09-12_12-04-47_Imagine.png ( 64 KB | 100 Downloads )

Title: Re: Reset ZoomFactor in CreateImage
Post by Slavcho on Sep 12th, 2017 at 7:09am
Have you tried using the CreateImage(100) overload? I'll test it from the demo project.

Title: Re: Reset ZoomFactor in CreateImage
Post by vremennyi on Sep 12th, 2017 at 7:12am

Slavcho wrote on Sep 12th, 2017 at 7:09am:
Have you tried using the CreateImage(100) overload? I'll test it from the demo project.

CreateImage calls CreateImage(100) - same result.

Title: Re: Reset ZoomFactor in CreateImage
Post by Slavcho on Sep 12th, 2017 at 7:27am
Right, the exported boundaries are incorrect if the diagram is zoomed. Try calling UpdateLayout after resetting until we fix that -

[code]
diagram.ZoomFactor = 100;
diagram.UpdateLayout();
var image = diagram.CreateImage();[/code]

Title: Re: Reset ZoomFactor in CreateImage
Post by vremennyi on Sep 12th, 2017 at 8:14am
Main question about blurried images. See Attachment1.

Slavcho wrote on Sep 12th, 2017 at 7:27am:
Right, the exported boundaries are incorrect if the diagram is zoomed. Try calling UpdateLayout after resetting until we fix that

It doesn't help)
First diagram in Demo, same code + UpdateLayout

Code (c++):

diagram.ZoomFactor = 100.0;
diagram.UpdateLayout();
var image = diagram.CreateImage();
var tempFileName = "D:\\Temp\\123.png";
Utilities.SaveImage(image, tempFileName);
Process.Start(tempFileName);

2017-09-12_13-13-51_Demo_vshost.png ( 103 KB | 118 Downloads )
2017-09-12_13-09-56_Imagine.png ( 65 KB | 94 Downloads )

Title: Re: Reset ZoomFactor in CreateImage
Post by Slavcho on Sep 12th, 2017 at 8:28am
I'm not seeing a blurred image after export, is your attachment the actual exported file or a screenshot of it in some application? What's the original zoom value when you click the export menu item? My export is attached, seems crisp enough.
123_001.png ( 88 KB | 95 Downloads )

Title: Re: Reset ZoomFactor in CreateImage
Post by vremennyi on Sep 12th, 2017 at 8:45am

Slavcho wrote on Sep 12th, 2017 at 8:28am:
I'm not seeing a blurred image after export, is your attachment the actual exported file or a screenshot of it in some application? What's the original zoom value when you click the export menu item? My export is attached, seems crisp enough.

Just downloaded Demo.CS again and added export menu item with same code again.

Can't attach screencast, uploaded here: https://www.dropbox.com/s/mcmmwl7myr2febn/2017-09-12_13-40-48.mp4?dl=0

Online preview is blurried))) Watch downloaded.

Title: Re: Reset ZoomFactor in CreateImage
Post by Slavcho on Sep 12th, 2017 at 8:59am
Yes, I've reproduced when exporting a very large image. Our developer will investigate.

Title: Re: Reset ZoomFactor in CreateImage
Post by Slavcho on Sep 12th, 2017 at 3:10pm
That seems a known problem with RenderTargetBitmap, e.g.
https://stackoverflow.com/questions/34745384/image-looks-blur-created-using-rendertargetbitamp-in-wpf

Our guess is it could be related to max texture size of video card, WPF being backed by DirectX... We'll try to find some work-around.

Title: Re: Reset ZoomFactor in CreateImage
Post by Slavcho on Sep 13th, 2017 at 10:56am
This build glues the exported bitmap from smaller RenderTargetBitmaps, that seems to fix the blurry output -
https://mindfusion.eu/_beta/wpfdiag351.zip

Also you should no longer have to set ZoomFactor.

Regards,
Slavcho

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.