濮阳杆衣贸易有限公司

主頁 > 知識庫 > FileUpload上傳圖片前實(shí)現(xiàn)圖片預(yù)覽功能(附演示動畫)

FileUpload上傳圖片前實(shí)現(xiàn)圖片預(yù)覽功能(附演示動畫)

熱門標(biāo)簽:玉林市機(jī)器人外呼系統(tǒng)哪家好 南陽外呼系統(tǒng)定制化 百度ai地圖標(biāo)注 蘋果手機(jī)凱立德地圖標(biāo)注 同安公安400電話怎么申請流程 合肥電銷外呼系統(tǒng)哪家公司做的好 預(yù)測式外呼系統(tǒng)使用說明 申請400電話手續(xù) 電話機(jī)器人軟件銷售工作
看看效果:
 
在專案中,創(chuàng)建aspx頁面,拉上FileUpload控件一個Image,將用來預(yù)覽上傳時的圖片。
復(fù)制代碼 代碼如下:

View Code
%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
!DOCTYPE html>
html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
title>/title>
/head>
body>
form id="form1" runat="server">
div>
table>
tr>
td style="vertical-align: top; width: 10%;">
fieldset>
legend>選擇圖片/legend>
asp:FileUpload ID="FileUpload1" runat="server" />
/fieldset>
/td>
td style="vertical-align: top; width: 90%;">
fieldset>
legend>預(yù)覽/legend>
asp:Image ID="Image1" runat="server" Visible="false" />
/fieldset>
/td>
/tr>
/table>
/div>
/form>
/body>
/html>

在Page_Init事件中,為FileUpload控件,注冊onchange客戶端事件。
復(fù)制代碼 代碼如下:

protected void Page_Init(object sender, EventArgs e)
{
this.FileUpload1.Attributes.Add("onchange", Page.ClientScript.GetPostBackEventReference(this.FileUpload1, "onchange"));
}

接下來,Insus.NET一個axd處理文檔,其實(shí)ImageProcessFactory.cs只是一個普能的類別,只實(shí)作了IHttpHandler接口。
復(fù)制代碼 代碼如下:

ImageProcessFactory.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.SessionState;
/// summary>
/// Summary description for ImageProcessFactory
/// /summary>
namespace Insus.NET
{
public class ImageProcessFactory : IHttpHandler,IRequiresSessionState
{
public ImageProcessFactory()
{
//
// TODO: Add constructor logic here
//
}
public void ProcessRequest(HttpContext context)
{
//Checking whether the UploadBytes session variable have anything else not doing anything
if ((context.Session["UploadBytes"]) != null)
{
byte[] buffer = (byte[])(context.Session["UploadBytes"]);
context.Response.BinaryWrite(buffer);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

為能能應(yīng)到axd文檔,需要在Web.Config中配置一下。
復(fù)制代碼 代碼如下:

View Code
configuration>
system.web>
httpHandlers>
add verb="*" path="PreviewImage.axd" type="Insus.NET.ImageProcessFactory"/>
/httpHandlers>
/system.web>
/configuration>

Ok,我們回到aspx.cs頁面中,要在page_Load中,怎監(jiān)控FileUpload控件是否有值變化:
復(fù)制代碼 代碼如下:

View Code
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
var ctrl = Request.Params[Page.postEventSourceID];
var args = Request.Params[Page.postEventArgumentID];
OnchangeHandle(ctrl, args);
}
}

在Page_Load中有一個方法OnchangeHandle(xxx,xxx):
復(fù)制代碼 代碼如下:

View Code
private void OnchangeHandle(string ctrl, string args)
{
if (ctrl == this.FileUpload1.UniqueID args == "onchange")
{
this.Image1.Visible = true;
Session["UploadBytes"] = this.FileUpload1.FileBytes;
this.Image1.ImageUrl = "~/PreviewImage.axd" ;
}
}
您可能感興趣的文章:
  • 基于jquery實(shí)現(xiàn)的上傳圖片及圖片大小驗(yàn)證、圖片預(yù)覽效果代碼
  • 上傳圖片預(yù)覽JS腳本 Input file圖片預(yù)覽的實(shí)現(xiàn)示例
  • js實(shí)現(xiàn)上傳圖片預(yù)覽的方法
  • js 上傳圖片預(yù)覽問題
  • javascript IE7 瀏覽器本地圖片預(yù)覽
  • 純JS實(shí)現(xiàn)的批量圖片預(yù)覽加載功能
  • JavaScript 圖片預(yù)覽效果 推薦
  • 兼容最新firefox、chrome和IE的javascript圖片預(yù)覽實(shí)現(xiàn)代碼
  • 手機(jī)圖片預(yù)覽插件photoswipe.js使用總結(jié)
  • 移動端點(diǎn)擊圖片放大特效PhotoSwipe.js插件實(shí)現(xiàn)

標(biāo)簽:淄博 臺州 揚(yáng)州 海南 南昌 南京 南京 嘉興

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《FileUpload上傳圖片前實(shí)現(xiàn)圖片預(yù)覽功能(附演示動畫)》,本文關(guān)鍵詞  FileUpload,上傳,圖片,前,實(shí)現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《FileUpload上傳圖片前實(shí)現(xiàn)圖片預(yù)覽功能(附演示動畫)》相關(guān)的同類信息!
  • 本頁收集關(guān)于FileUpload上傳圖片前實(shí)現(xiàn)圖片預(yù)覽功能(附演示動畫)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    常山县| 嘉兴市| 大连市| 天全县| 班玛县| 改则县| 汝城县| 杂多县| 大英县| 青田县| 阜新| 肥东县| 甘谷县| 开远市| 林甸县| 徐闻县| 隆林| 台安县| 伊春市| 陆河县| 麟游县| 阿拉尔市| 焦作市| 紫金县| 吉安县| 烟台市| 洮南市| 龙岩市| 青阳县| 五莲县| 泰宁县| 南和县| 曲靖市| 弋阳县| 镶黄旗| 岳普湖县| 龙川县| 卓资县| 会宁县| 公主岭市| 增城市|