如何在浏览器窗口中放置System.Drawing.Graphics对象(How to place a System.Drawing.Graphics object in browser window

编程入门 行业动态 更新时间:2024-10-28 18:35:38
如何在浏览器窗口中放置System.Drawing.Graphics对象(How to place a System.Drawing.Graphics object in browser window)

我想了解如何使用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/

更多推荐

本文发布于:2023-07-31 08:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1342555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浏览器   对象   窗口中   如何在   System

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!