Creating image maps for HTML files and export PNG

Hi,



I’d like to create html Image maps and png files. However the HTML exporter can’t do this.



tag description:



HTML map tag



I found an old discussion on this topic:



Html image map





Here’s what i’d like to do:



1) We start with a Visio drawing



2) I’d like to create a png file of a specific size e.g. 800x600 or “800 and fit the rest”.



3) I’d like to mark specific shapes, e.g. by ID or by a list of shape references.



4) Aspose should also create a file. The marked shapes are clickable - or more abstract - the click events can be handeled in HTML.



I added a simple example for further discussion.

Please open the “SimpleShape.html” of the ZIP file.

I added some extra docs here.

Thank you!

Hi Harald,


Thank you for contacting support. Please note that Aspose.Diagram API mimics the behavior of Microsoft Office Visio. You can generate a Visio diagram. Also, you can get specified sizes of shape graphics, but there is no way to handle click events because image maps are beyond the Microsoft Office Visio features. However, you can prepare a custom application to cater image map click events.

Please refer to the help topics there:
http://www.aspose.com/docs/display/diagramnet/Home

Please feel free to reply us in case of any confusion or questions.

Hi



thank you for your answer.





I wrote some sample code:



var diagram = new Diagram(@“C:\projects\AsposeTest\SimpleShapes.vsdx”);

var options = new ImageSaveOptions(SaveFileFormat.PNG);

var file = @“C:\projects\AsposeTest\SavePNG\test.png”;

diagram.Save(file, options);





The resulting image is 794x1123.





Two question:





1) Which mode do I have to use, to save only the area of visible shapes not the whole page? (Like the Viso exporter)





2) In the current example the blue rect dimension are 105,120 to 300, 235





So how do I get this coordinates in code?

Hi Harald,


Well, you can adjust Visio page sizes as shown in the following sample code:
https://forum.aspose.com/t/4884

Or

[C#]

ImageSaveOptions opts = new
ImageSaveOptions(SaveFileFormat.PNG);

opts.PageSize = new
PageSize(400f, 600f);


However, your requirement looks a bit different. We have logged an investigation to save only the area of Visio drawing where shapes reside. This task has been logged under the ticket id DIAGRAMNET-50210 in our issue tracking system. Your request has also been linked to this issue. We’ll keep you informed regarding any available updates.
Haraldf:
2) In the current example the blue rect dimension are 105,120 to 300, 235
You can get PinX, PinY, Width and Height (as shown in XForm_Prop.png) values by which the dimensions of a shape can be calculated.

Properties:
shape.XForm.PinX.Value;
shape.XForm.PinY.Value;
shape.XForm.Width.Value;
shape.XForm.Height.Value;

Please refer to the help topic:
http://www.aspose.com/docs/display/diagramnet/Setting+XForm+Data

Please feel free to reply us in case of any confusion or questions.

Hi Imran,



I tried your code (using Aspose.Diagram.dll 4.3.0.0).



There are two issues:



class Program

{

static void Main(string[] args)

{

var diagram = new Diagram(@“C:\projects\AsposeTest\SimpleShapes.vsdx”);

var opts = new ImageSaveOptions(SaveFileFormat.PNG)

{

PageSize = new PageSize(400f, 600f)

};



// result is 533 x 800 - not 400x600 as expected



var file = @“C:\projects\AsposeTest\SavePNG\test.png”;

diagram.Save(file, opts);



var page = diagram.Pages[0];

for(var i = 0; i
{

var shape = page.Shapes[i];

var xform = shape.XForm;



var x = xform.PinX.Value;

var y = xform.PinY.Value;

var w = xform.Width.Value;

var h = xform.Height.Value;



Console.WriteLine(“Shape: " + i);

Console.WriteLine(string.Format(”{0}, {1}, {2}, {3}", x, y, w, h));

}



// Console output:



/*

Shape: 0

2,12598425196851, 9,84251968503937, 2,04724409448819, 1,18110236220473

Shape: 1

4,56692913385827, 9,25196850393701, 1,65354330708661, 1,5748031496063

*/



// expected results (messured with photoshop in the PNG):

// bounding box blue rect: 71, 87 - 133, 81

// bounding box red circle: 240, 114 - 108, 108





Process.Start(file);

}

Hi Harald,

Thank you for your inquiry. We managed to replicate the problem of page size adjustment. We have logged this issue under ticket id DIAGRAMNET-50212 in our issue tracking system. Your request has also been linked to this issue. We will keep you informed regarding any available updates.

Haraldf:

/*

Shape: 0

2,12598425196851, 9,84251968503937, 2,04724409448819, 1,18110236220473

Shape: 1

4,56692913385827, 9,25196850393701, 1,65354330708661, 1,5748031496063

*/

// expected results (messured with photoshop in the PNG):

// bounding box blue rect: 71, 87 - 133, 81

// bounding box red circle: 240, 114 - 108, 108

Please note that Aspose.Diagram API mimics the behavior of Microsoft Office Visio. The XForm properties return correct values as shown on the shape sheet (XForm_Prop.png). These values are in inches. We can easily convert inches to millimeter as follows:

[C#]

Diagram diagram = new Diagram(@"c:\temp\SimpleShapes.vsdx");

foreach (Shape shape in diagram.Pages[0].Shapes)

{

    //FORMULA: Inches / .03937

    var x = shape.XForm.PinX.Value / .03937;

    var y = shape.XForm.PinY.Value / .03937;

    var w = shape.XForm.Width.Value / .03937;

    var h = shape.XForm.Height.Value / .03937;

    //String.Format("{0:0.00}", 123.4567);

    Console.WriteLine(string.Format("{0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}", x, y, w, h));

}

Result:

54.00, 250.00, 52.00, 30.00

116.00, 235.00, 42.00, 40.00

We hope, this helps.

Hi Imran,

I think I get it!

Thank you about the inch <-> cm transformation.

I still miss a factor. How can I convert from “cm” to Pixels in the PNG?

Is there a “dpi” faktor, that can be used?

Hi Harald,


Thank you for your inquiry. Yes, the dpi factor is important in this regard. Please have a look on this descriptive url: http://stackoverflow.com/questions/4767617/centimeter-to-pixel

We hope, this helps. Please feel free to reply us in case of any confusion or questions.

Hi Imran,



sorry I don’t understand :frowning:



The DIP factor must come from inside your renderer (or the Visio file or from Microsoft).



When saving the Visio File as PNG it’s rendered with a specific DPI size.



Edit:



I found out, that saving a 1x1 Inch square produces a 96x96 Pixel PNG.



Is this a Visio / Aspose.Diagram constant?



You can render a 10 Inch line as 1000 Pixels or as 2.



The code you gave me determines the DPI size of my current Windows screen.



How is this related to Aspose Diagram?

Hi Harald,


Thank you for being patient.
Haraldf:
class Program
{
static void Main(string[] args)
{
var diagram = new Diagram(@“C:\projects\AsposeTest\SimpleShapes.vsdx”);
var opts = new ImageSaveOptions(SaveFileFormat.PNG)
{
PageSize = new PageSize(400f, 600f)
};

// result is 533 x 800 - not 400x600 as expected
Imran Rafique:
We have logged this issue under ticket id DIAGRAMNET-50212 in our issue tracking system.
Our development team has completed their analysis. Please note that the width and height of page size are in inches, which is 400 and 600. The result PNG size is 533 x 800, these values are in pixels, the default pixel value is "inch value"96/72. We could find the result as 533800. Since, the issue id DIAGRAMNET-50212 has been marked as “Won’t Fix”.

Second, we can get DPI size using Aspose.Imaging API. Please have a look on this sample code:

[C#]
Aspose.Imaging.FileFormats.Png.PngImage image = (Aspose.Imaging.FileFormats.Png.PngImage)Aspose.Imaging.Image.Load(“C:/temp/ test.png”);
Console.WriteLine(image.HorizontalResolution

  • “:” + image.VerticalResolution);

You can even change the DPI resolution if you require: Setting Resolution for PNG Images

Please feel free to reply us in case of any confusion or questions.

Hello Imran,



“inch value”*96/72 makes sense, as I came to the same result by a sample.





My question was on the exporter (about Setting/Getting) the DPI and not about the importer.





So - is the 96 a constant of the exporter

or is there some



ImageSaveOptions.DPI… constant/property?



Thank you.



(I am preparing a new full sample)

Hi, Harald


Thank you for the clarification. We’re in communication with our development and will get back to you soon.

Hi Harald,


Thank you for being patient. Yes, 1 inch is 72 points and 96 pixels and we can get pixels per inch using the ImageSaveOptions.Resolution property. We hope, this helps.

Hi Harald,


Thank you for being patient. We have a good news for you that the ticket ID DIAGRAMNET-50210 has now been resolved. If there is no issue in the QA phase, then this fix will be included in the next version of Aspose.Diagram for .NET 17.01. We’ll inform you via this forum thread as soon as the new release is published.

The issues you have found earlier (filed as DIAGRAMNET-50210) have been fixed in Aspose.Diagram for .NET 17.1.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.