抢先形象 [英] getting a preiew of an image

查看:81
本文介绍了抢先形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在尝试上传图片.我已将上传控件添加为网页

Hi all,
I am trying to upload an image.I haev added an upload control to my web page as

Upload front Image<input id="File1"
        style="Z-INDEX: 100; LEFT: 300px; WIDTH: 288px; POSITION: absolute; TOP: 120px; HEIGHT: 22px"
        type="file" size="28" name="Upload" runat="server" >


<div>
        <asp:Button ID="btnPreview" runat="server" Text="Preview Images"

            onclick="btnPreview_Click" />
    </div>


<asp:Panel id="Panel1" runat="server" Height="1000px" Width="800px" Visible = "true">
    <asp:Image ID="Image6" runat="server" />
    </asp:Panel>



当用户单击预览按钮时,我想在图像控件中显示选定的图像.
我在 File1.Value 中获取上载文件的路径,并将其分配为ImageUrl,但未显示任何图像.
选择的图像是.bmps.
任何帮助..请吗?



When the user clicks on a preview button i want to display the selected image in an image control.
i am getting teh path of the uploaded file in File1.Value and assigning it as teh ImageUrl but no image is being displayed.
Teh images in have selected are .bmps.
Any help.. please?

protected void btnPreview_Click(object sender, EventArgs e)
      {
          if (File1.PostedFile != null)
          {


Image6.ImageUrl = File1.Value;


}


}


}


}

推荐答案

因为您必须将上传的文件保存在服务器中的一个位置,并将该位置的url提供给HtmlImage对象
下面显示的代码可以帮助您了解
As you have to save the uploaded file in your server at one location, and give the url of that location to the HtmlImage object
shown below code may help you to understand
string path = Server.MapPath("") + @"\UserImages\image" + CurrentImage + ".jpg";
            //This will create one path for CurrentImage.jpg
            FileStream fs = File.Create(path);
            fs.Write(ImageUpload.FileBytes, 0, ImageUpload.FileBytes.Length);
            fs.Close();
           //saving the uploaded file in that path
            Image6.ImageUrl=path;// or \UserImages\image" + CurrentImage + ".jpg";


在您的项目中创建文件夹并保存图像并从中检索
Create folder in ur project and save the images on it and retrivew from it


以下几种方法(目前,我的机器(开发)发生故障,因此我无法检查您的代码)

在Asp.net的图像控件中显示上载的图像 [ ^ ]
显示图像使用ASP.Net AsyncFileUpload Control上传而没有页面刷新或回发后 [使用JavaScript和客户端回调上传和预览图像 [
Here some ways(Currently my machine(development) is down so I can''t check your code)

Show Uploaded Image in Image Control in Asp.net[^]
Display image after upload without page refresh or postback using ASP.Net AsyncFileUpload Control[^]
Upload and Preview Images Using JavaScript and Client Callbacks [^]


这篇关于抢先形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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