Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic some distortion when node move to certain places (Read 4418 times)
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
some distortion when node move to certain places
Apr 3rd, 2013 at 7:34pm
Print Post  
Hi Stoyan,

I noticed sometimes there's a little distortion for node(size fit to image, and image all 1bpp bitmaps). When I put them(same image) here and there, some of them will change in display. Is this related to GDI+ or diagram itself?

Kyle
  

1_001.png ( 2 KB | 163 Downloads )
1_001.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: some distortion when node move to certain places
Reply #1 - Apr 4th, 2013 at 8:09am
Print Post  
Hi,

ResizeToFitImage considers the bitmap's intrinsic DPI settings (Image.HorizontalResolution / VerticalResolution) when resizing the node, and that might actually scale the image if the display's DPI is different, leading to some bitmap resize artifacts. You could try directly setting the node's Bounds size to image.Width x image.Height to avoid that (also assuming you are using Pixel as MeasureUnit, which you used to some time ago if I recall correctly).

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: some distortion when node move to certain places
Reply #2 - Apr 4th, 2013 at 5:18pm
Print Post  
Thank you first.

However for the same image on same DiagramView, the ResizeToFitImage should generate the same result?

Yes, I'm using Pixel as measurement but I need to scale based on bitmap's resolution.

Stoyo wrote on Apr 4th, 2013 at 8:09am:
Hi,

ResizeToFitImage considers the bitmap's intrinsic DPI settings (Image.HorizontalResolution / VerticalResolution) when resizing the node, and that might actually scale the image if the display's DPI is different, leading to some bitmap resize artifacts. You could try directly setting the node's Bounds size to image.Width x image.Height to avoid that (also assuming you are using Pixel as MeasureUnit, which you used to some time ago if I recall correctly).

I hope that helps,
Stoyan

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: some distortion when node move to certain places
Reply #3 - Apr 4th, 2013 at 5:32pm
Print Post  
It probably generates the same result in terms of node size. However when a bitmap is drawn scaled, some of its pixel rows and columns must be either duplicated or deleted, and it might depend on current coordinates which ones GDI+ chooses to. You could also check if the nodes have integer coordinates for both position and size, and if not - round them down to integer.
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: some distortion when node move to certain places
Reply #4 - Apr 4th, 2013 at 7:23pm
Print Post  
I checked, both of them rounded to integer coordinates. It's pixel measurement, it will be integer anyway.
Seems it's related to x-coordinate, one image shows correct every 7 pixels then missed one line 7 pixels, then good again for 7 pixels then missed ... only once it's 8 pixels. Weird...

Stoyo wrote on Apr 4th, 2013 at 5:32pm:
It probably generates the same result in terms of node size. However when a bitmap is drawn scaled, some of its pixel rows and columns must be either duplicated or deleted, and it might depend on current coordinates which ones GDI+ chooses to. You could also check if the nodes have integer coordinates for both position and size, and if not - round them down to integer.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: some distortion when node move to certain places
Reply #5 - Apr 5th, 2013 at 8:32am
Print Post  
It could be a clipping problem actually, since ShapeNodes are clipped to their Shape outline. Try custom drawing them, or overriding the Draw method to avoid clipping:

Code
Select All
private void Form1_Load(object sender, System.EventArgs e)
	var image = (Bitmap)Image.FromFile("rect_frame.png");
	image.SetResolution(196, 196);
	diagram.MeasureUnit = GraphicsUnit.Pixel;
	for (int i = 0; i < 50; i+= 5)
	{
		var node = diagram.Factory.CreateShapeNode(i, i * 2, 5, 5);
		node.Image = image;
		node.CustomDraw = CustomDraw.Full;
		node.ResizeToFitImage();
	}
}

private void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
	var shape = e.Node as ShapeNode;
	if (shape != null)
		Utilities.DrawImage(e.Graphics, shape.Image, shape.Bounds, ImageAlign.Stretch);
} 



The nodes above show missing lines when not custom drawn but have Transparent enabled, which probably happen due to some imprecision in clipping regions. They are drawn fine if only drawing stretched images with custom drawing.

We also have a ClipImage property in the WPF version that controls whether images are clipped by the shape, we'll implement it in Windows forms too for next release.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: some distortion when node move to certain places
Reply #6 - Apr 12th, 2013 at 2:15pm
Print Post  
Thank you Stoyan! I will wait for the next release with Clip option. I'm not sure I can handle those dpi/resolution if I write a owner draw routine myself.

I just tried to copy your code to my project. When I set node's CustomDraw to CustomDraw.All. It draws nothing and "diagram_NodeDraw" never triggered. Anything wrong with my side?
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: some distortion when node move to certain places
Reply #7 - Apr 18th, 2013 at 8:34pm
Print Post  
Today I upgrade to Flowchart 6.0.2. It's a little worse for this problem - it will show as one or two pixels clipped every 3 pixels move in horizontal direction.

Looking forward to your clip option.

Why when I add handler for Diagram.DrawNode, it doesn't take effect - it never goes to the handler code? Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: some distortion when node move to certain places
Reply #8 - Apr 19th, 2013 at 6:42am
Print Post  
Hi,

Set CustomDraw to Full and Transparent to false to get DrawNode raised.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: some distortion when node move to certain places
Reply #9 - Apr 19th, 2013 at 8:42pm
Print Post  
Thanks. I have got the DrawNode triggered by setting Transparent = false. But I finally found out the reason of the distortion - I thought I was setting the location for each node to integers without portions but that was not always true - which causes the node image to loose one line.
I have to adjust the Location to make sure they're integer aligned before each call to Node.Move(...).  Grin
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint