如何将ascx usercontrol转换为要保存在服务器上的图像?

时间:2011-11-17 23:42:59

标签: c# asp.net ascx

我有一个运输标签ascx控件,我需要将渲染的控件转换为图像,然后将其保存在服务器上。

这可能吗?

2 个答案:

答案 0 :(得分:0)

不完全确定您要查找的内容,但您可以在用户控件中放置图像并显示图像或页面路径。

//option 1: expose the image path
string imageUrl = MyUserControl.ImagePath; 

//option 2: expose the image control
Image img = MyUserControl.SomeImage; //image

当您说要将图像保存在服务器上时,我有点困惑 - 如果您在用户控件中显示图像,那么服务器上是否已有图像?你想在其他地方保存图像吗?

答案 1 :(得分:0)

您无法将Aspx控件真正转换为图像;但是,您可以将Windows窗体的控件转换为图像!您应该将控件重新创建为Windows窗体(是的,这适用于Web应用程序),通过将表单暴露必要的属性“绘制”到位图来填充数据。如果您更喜欢Windows Presentation Foundation,那么您也可以这样做。

我之前必须使用windows form draw to image为aspx应用程序创建动态图表,结果非常棒。