Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Changing the diagram page location (Read 3208 times)
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Changing the diagram page location
Apr 3rd, 2013 at 8:47am
Print Post  
Hi'

I'm experiencing some problems when exporting a PNG since all the Diagramitems placed with negative values in their location are cropped.

The following code causes this behaviour:

var encoder = new PngBitmapEncoder();            encoder.Frames.Add(BitmapFrame.Create(CurrentPage.CreateImage(200)));


Can you provide me with:

1) since I need to call ResizeToFit on the diagram (I've a tree which became very large), I need a method to "reset" or offset the origin of a DiagramPage so that all the items will be moved in the positive axes. E.g. after calling ResizeToFit, the diagram bounds are updated to -1000,-1000, 1000, 1000. But I need that all the items are placed into a diagram located at 0,0,2000,2000.

2) I need a way to move all the items to another location (including links) programmatically so that link's shapes are preserved (as if dragged by mouse when all of them are selected).

Can you point me in the right direction?

A.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing the diagram page location
Reply #1 - Apr 3rd, 2013 at 10:45am
Print Post  
Hi,

You can use the following method to export with negative coordinates:

Code
Select All
var element = diagram;
var bmpSource = new RenderTargetBitmap(
	(int)element.ActualWidth,
	(int)element.ActualHeight,
	96, 96, PixelFormats.Default);
bmpSource.Render(element);
var image = BitmapFrame.Create(bmpSource);
Utilities.SaveImage(image, dlg.FileName);
 



You could use the MoveSelection method from this topic to move multiple items around, but might have to save/restore selection state: http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=122710007...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Re: Changing the diagram page location
Reply #2 - Apr 3rd, 2013 at 12:01pm
Print Post  
Unfortunately I'm experiencing some issues with you code.

I'm using a TabbedDiagramView and If I use the CurrentPage as the Element to be rasterized, the behaviour is very weird
and depends on the zoom and pan (but not consistently).
I cannot find the right combination to produce a bitmap not cropped with the right size.

One note: The TabbedDiagramView has been retemplated to include a Ruler (you posted me the code some weeks ago) if it matters.
  
Back to top
 
IP Logged
 
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Re: Changing the diagram page location
Reply #3 - Apr 3rd, 2013 at 12:51pm
Print Post  
To be more precise, I've found that the behaviour is correct if I manually scroll with the mouse the tabbeddiagramview to top left before rendering. Moreover the output depends on the page current zoom level.

Can you provide me with additional instructions to make the rendering independent of scroll (and zoom)?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Changing the diagram page location
Reply #4 - Apr 4th, 2013 at 7:51am
Print Post  
Setting var element = diagram.DocumentPlane; in the code above will help avoiding the scroll offset, but not the ZoomFactor scale transform. You will have to temporarily change the zoom level to 100 when exporting, or generate the image from a copy of the diagram (e.g. created by calling LoadFromString(currentPage.SaveToString())) to avoid changes on screen.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Re: Changing the diagram page location
Reply #5 - Apr 12th, 2013 at 7:40am
Print Post  
Yes, it helped! Thanks
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint