我想了解如何使用C#在我的浏览器窗口中绘制图像 - 以及已经存在的其他HTML对象。 (想法:放置允许用户改变图像的按钮和表单。)我在Linux上的Mono中这样做,但我希望这个东西是可移植的。 到目前为止我想出的是:
public virtual void button1Clicked (object sender, EventArgs args) { int height = 300; int width = 300; Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); // //Draw something on g here // Response.ContentType = "image/gif"; bmp.Save(Response.OutputStream, ImageFormat.Gif); g.Dispose(); bmp.Dispose; }这将清除浏览器窗口,然后显示图像,这不是我想要的。 经过广泛搜索后,我找到了以下教程, http : //www.dreamincode.net/forums/topic/67275-the-wonders-of-systemdrawinggraphics/ ,其中说我应该尝试在窗口中使用Handle来控制某些控件,或者CreateGraphics()方法。 我的.aspx页面中的“button1”或实体的任何其他ID似乎都不存在。 那是因为我正在使用Mono吗?
总结一下,在C#+ asp.net中绘制浏览器窗口的最佳方法是什么?
I'd like to understand how to use C# for drawing an image in my browser window - alongside other HTML objects that are already there. (Idea: To place buttons and forms that allow the user to alter the image.) I am doing this in Mono on Linux, but I'd like the thing to be portable. What I came up with so far is:
public virtual void button1Clicked (object sender, EventArgs args) { int height = 300; int width = 300; Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); // //Draw something on g here // Response.ContentType = "image/gif"; bmp.Save(Response.OutputStream, ImageFormat.Gif); g.Dispose(); bmp.Dispose; }This clears the browser window and then displays the image, which is not what I wanted. After extensive search I found the following tutorial, http://www.dreamincode.net/forums/topic/67275-the-wonders-of-systemdrawinggraphics/ which says I should try to use a Handle on some control in my window, alternatively the CreateGraphics() method. Neither of these seem to exist for my "button1" or any other id of an entity in my .aspx page. Is that because I'm using Mono?
To sum up, what is the best way to draw inside a browser window in C# + asp.net??
最满意答案
我前段时间做了同样的事情,那就是如果要在iFrame或Image控件中使用它,你必须将图形对象/位图保存到某个位置。
如果您不想将其保存到某个位置,请尝试在页面上使用服务器脚本: http : //www.developerfusion.com/article/2569/creating-images-on-the-fly-with-aspnet/
i had the same thing to do some time ago, the thing is that you will have to save your graphic object/bitmap to a location if you want to use it in an iFrame or Image control.
If you don't want to save it to a location, try using a server script on your page : http://www.developerfusion.com/article/2569/creating-images-on-the-fly-with-aspnet/
更多推荐
发布评论