Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Reset ZoomFactor in CreateImage (Read 4384 times)
vremennyi
YaBB Newbies
*
Offline



Posts: 5
Joined: Sep 12th, 2017
Reset ZoomFactor in CreateImage
Sep 12th, 2017 at 6:49am
Print Post  
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)
Select All
<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++)
Select All
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 )
123.png
Back to top
 
IP Logged
 
vremennyi
YaBB Newbies
*
Offline



Posts: 5
Joined: Sep 12th, 2017
Re: Reset ZoomFactor in CreateImage
Reply #1 - Sep 12th, 2017 at 7:04am
Print Post  
Without reseting ZoomFactor to 100% just getting transparent borders.
  

2017-09-12_12-04-47_Imagine.png ( 64 KB | 99 Downloads )
2017-09-12_12-04-47_Imagine.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: Reset ZoomFactor in CreateImage
Reply #2 - Sep 12th, 2017 at 7:09am
Print Post  
Have you tried using the CreateImage(100) overload? I'll test it from the demo project.
  
Back to top
 
IP Logged
 
vremennyi
YaBB Newbies
*
Offline



Posts: 5
Joined: Sep 12th, 2017
Re: Reset ZoomFactor in CreateImage
Reply #3 - Sep 12th, 2017 at 7:12am
Print Post  
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.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: Reset ZoomFactor in CreateImage
Reply #4 - Sep 12th, 2017 at 7:27am
Print Post  
Right, the exported boundaries are incorrect if the diagram is zoomed. Try calling UpdateLayout after resetting until we fix that -

Code
Select All
diagram.ZoomFactor = 100;
diagram.UpdateLayout();
var image = diagram.CreateImage(); 

  
Back to top
 
IP Logged
 
vremennyi
YaBB Newbies
*
Offline



Posts: 5
Joined: Sep 12th, 2017
Re: Reset ZoomFactor in CreateImage
Reply #5 - Sep 12th, 2017 at 8:14am
Print Post  
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++)
Select All
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-13-51_Demo_vshost.png
2017-09-12_13-09-56_Imagine.png ( 65 KB | 94 Downloads )
2017-09-12_13-09-56_Imagine.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: Reset ZoomFactor in CreateImage
Reply #6 - Sep 12th, 2017 at 8:28am
Print Post  
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 )
123_001.png
Back to top
 
IP Logged
 
vremennyi
YaBB Newbies
*
Offline



Posts: 5
Joined: Sep 12th, 2017
Re: Reset ZoomFactor in CreateImage
Reply #7 - Sep 12th, 2017 at 8:45am
Print Post  
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.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: Reset ZoomFactor in CreateImage
Reply #8 - Sep 12th, 2017 at 8:59am
Print Post  
Yes, I've reproduced when exporting a very large image. Our developer will investigate.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: Reset ZoomFactor in CreateImage
Reply #9 - Sep 12th, 2017 at 3:10pm
Print Post  
That seems a known problem with RenderTargetBitmap, e.g.
https://stackoverflow.com/questions/34745384/image-looks-blur-created-using-rend
ertargetbitamp-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.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: Reset ZoomFactor in CreateImage
Reply #10 - Sep 13th, 2017 at 10:56am
Print Post  
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
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint