1

Hello so I have an interesting question for everyone. I have a WPF application that generates an html preview of a report based on Database data and user input. My currently dilemma is that I have a HTML canvas that is created by C# as follows:

Canvas myCanvas = new Canvas();
myCanvas.Name = "cvsMyCanvas";
myCanvas.width = userDefinedByTtextBox;
myCanvas.height = userDefinedByTtextBox;
myCanvas.Visibility = Visibility.Collapsed //Don't show the canvas just yet

My question is how do I get an image that I have saved locally to the computer on the canvas in a specific position. (i.e. A HTML Image tag object that is generated by C# and use the move to functionality)

(This is a rough example of how I think it should work but this is what I need the help on) Example:

string htmlImage = "<img id=\"myImage\" src=\"C:\\Temp\\img.png\">";
htmlImage.moveTo(x,y);

...again the above code is an example of what it is I am trying to do. If anyone could help me out that would be great! Also if I did not provide enough information please let me know and I will let provide it.

There seems to be some confusion on what it is I am trying to do, it is most likely my fault do to lack of explanation so allow me to elaborate more. I have images saved in a folder in my temp directory I. I am running a WPF application that has a WebBrowser control that I am using to display HTML. The HTML that is used in that WebBrowser is created in the C# code behind. I am trying to create a canvas that is displayed in the WebBrowser with the images that I have saved in my temp folder. The code I have provided above apparently will not work for what I am trying to accomplish because there is no way to create a canvas in C# and use it in HTML. Let me know if this helps shed some light on this predicament or if even more explanation is required.

4

1 回答 1

1

如果要从 C# 生成 HTML5 代码,生成的 HTML 代码应如下所示:

context = canvas.getContext('2d');

    var image = new Image();
    image.src = <your path>;
    image.onload = function() {
            context.drawImage(image, x, y, w, y);
        }

然后,只需将其存储在 String 或 StringBuilder

于 2012-11-28T14:39:19.640 回答