views:

148

answers:

1

I faced this problem and after an extensive research I found its root cause and a workaround that can be useful for other people.

The icon decorator becomes "blurred" because its positioning on the shape and the conversion from pixels to inches.

Usually the drawing surface of the Domain Specific Language has a resolution of 96dpi and the Icon Decorators are positioned using an offset of 0.06 inches. Translating it to pixels it becomes an offset of 5.76 pixels in the drawing surface. As it is not possible to draw a "half pixel" on the screen the GDI+ adjusts the image in an attempt to emulate the "haf pixel" positioning. That is the reason why the image becomes blurred.

My suggestion as workaround, is to use the Horizontal Offset and the Vertical Offset properties of the Icon decorator class for fixing the "half pixel" decorator position. If you use the "0.0025" inches as vertical and horizontal offsets, when the image positioning is translated from inches to pixels it becomes 6 pixels, instead of 5.76. It happens because the offset now is the default value 0.06 inches plus the offset you set 0.0025 = 0.0625.

I also found that using png images with transparency causes the image blurring, even using the offset workaround I suggested here. Converting the image to bitmap format fixes the problem.

If someone also has any suggestions for fixing the problem, please add your solution or workaround.

A: 

Hello,

I fixed the blurred problem by creating a new Bitmap:

Under the overridden method

public override System.Drawing.Image GetDisplayImage(ShapeElement parentShape)

I call my custom method FixBitmap

Bitmap imageFixed = DynamicImageHelper.FixBitmap(image, out dynamicOffset);

This method receives the original image that DSL would show, but instead returns the exact same image but created as a new Bitmap

Bitmap fixedImage = new Bitmap(original, original.Width, original.Height);
return fixedImage;

If you check the new instance properties there are little differences (I don't quite remember which because i implemented this about 1 year ago). Also, i mostly use .png files with transparency and they look exactly as they are.

Hope this helped. If you need any further help, do not hesitate, Regards, Luís

Luis Filipe