简体   繁体   English

在图片框中显示图像字符串数据。

[英]Displaying image string data in picture box.

I've to display a image in a picture box in VisualWebGui. 我必须在VisualWebGui的图片框中显示图像。 I've image in string format. 我有字符串格式的图像。

string ImageString_P;
FileStream fs_P = new FileStream(LocalDirectory + "Page_2.tif", FileMode.Open, FileAccess.Read);

byte[] picbyte_P = new byte[fs_P.Length];
fs_P.Read(picbyte_P, 0, Convert.ToInt32(fs_P.Length));
ImageString_P = Convert.ToBase64String(picbyte_P);

Now, how can I display this image(ImageString_P) in the picture box. 现在,如何在图片框中显示此图像(ImageString_P)。 Should I create the image of this string data or can I directly display this data in the PictureBox? 我应该创建此字符串数据的图像还是直接在PictureBox中显示此数据?

If I'll create the image in a path(suppose “c:\\xyz.jpg”) . 如果要在路径中创建图像(假设“ c:\\ xyz.jpg”)。 How it (xyz.jpg) will be displayed in the picturebox. 图片(xyz.jpg)的显示方式。

Visual WebGui is a web application and as such it basically needs to let the browser specifically request any graphics data that should be rendered, which is fundamentally different from that of desktop applications, where you can simply assign the graphics data itself to the image property of a PictureBox. Visual WebGui是一个Web应用程序,因此它基本上需要让浏览器专门请求应呈现的任何图形数据,这与桌面应用程序根本不同,在桌面应用程序中,您可以简单地将图形数据本身分配给的image属性。图片框。

If you study how a webpage with a PictureBox is rendered to the browser in Visual WebGui, you will see that the PictureBox is rendered as an img tag with the source being set to an Url, which is responsible for serving the image to the browser. 如果研究在Visual WebGui中如何将具有PictureBox的网页呈现给浏览器,您将看到PictureBox呈现为img标签,其源设置为Url,该URL负责将图像提供给浏览器。 When the browser sees that Url on the img tag, it issues another request to the server for the contents of that Url. 当浏览器在img标签上看到该Url时,它将向服务器发出对该Url内容的另一个请求。 This "secondary" request is called a gateway request in Visual WebGui. 此“辅助”请求在Visual WebGui中称为网关请求。

To serve the graphics to the browser, you need some kind of Gateway in your Visual WebGui application. 要将图形提供给浏览器,您在Visual WebGui应用程序中需要某种网关。 There are a few types of predefined gateways in Visual WebGui, like for Images (ImageResourceHandle) and icons (IconResourceHandle), but in this case you have a dynamically generated image, so you will need to define your own gateway to serve the graphics contents.... or you can write the image data to, say, Resources\\Images folder of your application and then use an ImageResourceHandle to reference it. Visual WebGui中有几种类型的预定义网关,例如图像(ImageResourceHandle)和图标(IconResourceHandle),但是在这种情况下,您具有动态生成的图像,因此您将需要定义自己的网关来提供图形内容。 ...,或者您可以将图像数据写入应用程序的Resources \\ Images文件夹,然后使用ImageResourceHandle进行引用。

Defining your own gateways in Visual WebGui is very simple, and you can see quite a few examples here . 在Visual WebGui中定义自己的网关非常简单,您可以在此处看到很多示例。

Hope this helps, Palli 希望这会有所帮助,Palli

You can do like this: 您可以这样:

string ImageString_P;
FileStream fs_P = new FileStream(LocalDirectory + "Page_2.tif", FileMode.Open, FileAccess.Read);

byte[] picbyte_P = new byte[fs_P.Length];
this.picMyPicture.Image = new DynamicStreamResourceHandle(contentBitmap, "image/jpeg");

and it should render fine. 它应该可以渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM