Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Draw a image (Read 2977 times)
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Draw a image
Jun 30th, 2011 at 3:40am
Print Post  
I draw a image in a TableNode, but it looks not very clear, lines in the image are little thick. I use same code to draw this image in my sample project, the imgae can be displayed clearly. I changed the property SmoothingMode of DiagramView but I did not make it. Is there anybody can help me ?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Draw a image
Reply #1 - Jun 30th, 2011 at 6:13am
Print Post  
Have you set ImageAlign to a value that does not stretch the image?
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Draw a image
Reply #2 - Jun 30th, 2011 at 11:41pm
Print Post  
I set value Center, Fit to ImageAlign, but the problem stiil is there. I set the image location x = Bounds.X + 2, y = Bounds.Y + 2, but actuall the 2 means 5 pixel, not only 2 pixel. I think that I shall call DeviceToDoc method to convert it but I do not know how. I guess metric of coordinate and size cause this problem.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Draw a image
Reply #3 - Jul 1st, 2011 at 6:26am
Print Post  
How are you setting its location, are you custom-drawing the image?

GDI+ renders images a little bit blurred if they don't start exactly at a device pixel, so our image drawing code aligns images to pixels by calling ClientToDoc(DocToClient(point)); if you are custom-drawing images, you will have to do something similar.

You might also set MeasureUnit to Pixel to avoid conversions, but with that you will have to change the values of all size related properties to ones appropriate for pixels.

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


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Draw a image
Reply #4 - Jul 1st, 2011 at 10:16pm
Print Post  
Thanks, show my source code to you:

public override void Draw(IGraphics graphics, RenderOptions options)
{
base.Draw(graphics, options);
this.ImageAlign = MindFusion.Drawing.ImageAlign.Center;
DrawShapeHead(graphics);
}

protected virtual void DrawShapeHead(IGraphics graphics)
{
System.Drawing.Image image = System.Drawing.Image.FromFile("SEC.png");

// 2. Show image
Rectangle iconSizePixels = new Rectangle(0, 0, image.Width, image.Height);
RectangleF imageSize = MindFusion.Utilities.DeviceToDoc(graphics, iconSizePixels);
graphics.DrawImage(image, Bounds.X + 2, Bounds.Y + 2, imageSize.Width, imageSize.Height);
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Draw a image
Reply #5 - Jul 2nd, 2011 at 8:42am
Print Post  
It should look like this:

Code
Select All
graphics.DrawImage(image, AlignToPixel(ControlPoints[0]));

PointF AlignToPixel(PointF point)
{
	return diagramView.ClientToDoc(diagramView.DocToClient(point));
} 



The DrawImage(image, point) method draws the image in its native size disregarding the measure unit, so you don't have to convert and specify the image size.

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


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Draw a image
Reply #6 - Jul 3rd, 2011 at 12:45am
Print Post  
It can work, image can be show clearly, thank you. But the location is not correct. I want to show the image at 2 pixel down and 2 pixel right from the left-top corner of TableNode. How to do this ???

Below code can show image at correct position but it is not clear.
PointF p = new Point((int)(Bounds.X + 2), (int)(Bounds.Y + 2));
graphics.DrawImage(image, p);

Below code can show image clearly but the location is not the place I want.
PointF p = this.Parent.PixelToUnit(new Point((int)(Bounds.X + 2), (int)(Bounds.Y + 2)));
graphics.DrawImage(image, p);
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Draw a image
Reply #7 - Jul 3rd, 2011 at 8:11am
Print Post  
Try this:

Code
Select All
PointF mmPos = Bounds.Location;
Point pxPos = diagramView.DocToClient(mmPos);
pxPos.Offset(2, 2);
mmPos = diagramView.ClientToDoc(pxPos);
graphics.DrawImage(image, mmPos);
 



or add offset parameters to AlignToPixel to keep it as a utility method:
Code
Select All
PointF AlignToPixel(PointF point, int dx, int dy)
{
	Point pxPos = diagramView.DocToClient(point);
	pxPos.Offset(dx, dy);
	return diagramView.ClientToDoc(pxPos);
} 



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


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Draw a image
Reply #8 - Jul 3rd, 2011 at 11:43pm
Print Post  
Thanks a lot , it can work fine.

But I have to convert location twice, looks it is not graceful
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint