如何在没有extrat的情况下从zip设置picturebox图像位置? [英] how to set picturebox image location from zip without extrat?

查看:107
本文介绍了如何在没有extrat的情况下从zip设置picturebox图像位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从zip文件中设置图片框而不提取zip。我的代码:

I want to set picture box from zip file without extract zip. my code:

ZipFile zip = new ZipFile("data.zip");
using (Stream s = zip["p3.png"].OpenReader())
{
    picturebox.ImageLocation = s.ToString();
}



图片框显示错误图片。


Picture Box Show error image.

推荐答案

您使用的是Image控件还是PictureBox? ?你已经用ASP.NET标签发布了这个问题,但我认为图片框用于winform应用程序而不是web应用程序或ASP.NET。



如果你正在使用在Windows应用程序中,使用Image属性而不是ImageLocation。请尝试以下过程:



从流中的图像创建一个Bitmap对象。



然后使用这个Bitmap对象用于设置图片框的Image属性。



以下是一些更多细节:



http://msdn.microsoft。 com / en-us / library / system.windows.forms.picturebox.image(v = vs.110).aspx [ ^ ]
Are you using Image control or PictureBox? You have posted the question with ASP.NET tag but I think picture box is used in winform applications and not in web applications or ASP.NET.

If you are using windows application, use the Image property instead of ImageLocation. Try the following process:

Create a Bitmap object from the image in your stream.

Then use this Bitmap object to set the Image property of your picture box.

Here are some more details:

http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image(v=vs.110).aspx[^]


第一个解决方案很好。正确的代码:

First Solution is Good. correct code:
ZipFile zip = new ZipFile("data.zip");
using (Stream s = zip["p3.png"].OpenReader())
{
    Bitmap bitmap= new Bitmap(s);
    PictureBox picturebox.Image = bitmap;
}


这篇关于如何在没有extrat的情况下从zip设置picturebox图像位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆