图片预览器(类似百度)

此预览器,一次只能翻页十张图片,开发人员可根据自己需要,修改前台代码。

==============================页面代码

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UpFilesAndPreview.aspx.cs" Inherits="WebFramework.CommonUpFiles.UpFilesAndPreview" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片预览器</title>
<base target="_self" />
<style type="text/css">
#show{height:auto;width:700px; text-align:center; margin-bottom:15px;border:1px solid #FFFFFF;display: inline-table}
#show img{ text-align:center; }
#container{  height:auto; width:613px; text-align:center; display: inline-table}
#left{ height:97px; width:24px; float:left; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453754.p.gif); margin-top:5px; margin-right:10px;}
#middle{ height:109px;  width:545px; float:left; overflow:hidden;}
#thumblist{ width:1090px;}
#thumblist div { width:109px; height:109px; text-align:center; float:left}
.cc{width:109px; height:109px; text-align:center; float:left; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011452785.p.gif)}
#thumblist div span { width:95px; height:95px; margin:6px !important;margin:3px; margin-top:6px; border:1px solid #FFFFFF; background-color:#000000; vertical-align:middle; line-height:95px; display:block}
#thumblist div span img { width:100%; height:100%; display:block}
#right{height:97px; width:24px; float:left;  background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453926.p.gif);margin-top:5px; margin-left:10px}
</style>

<script language="javascript" type="text/javascript">
    function set_txtSelectFileName(fileName){
        window.document.getElementById("txtSelectFileName").value = fileName;
        window.document.getElementById("img_Show_ItemID").src = '<%=GetFileHTTPPath %>' + fileName;
       
        if(fileName == '')
            window.document.getElementById("img_Show_ItemID").style.display = "none";
        else
            window.document.getElementById("img_Show_ItemID").style.display = "";
    }
</script>
</head>
<body style="background-color:#FFFFFF; text-align:center" > 
<form runat="server" id="form1">
<div id="container" style="border-right: 1px solid; border-top: 1px solid; border-left: 1px solid; border-bottom: 1px solid;background-color: aliceblue;">
    <div style="width:100%; height:31px; font-weight: bold; font-size: 21pt; vertical-align: middle; font-style: normal; font-family: 华文行楷, 华文宋体; text-align: center;">图片预览器</div>
    <div><hr  style="width:100%; height:1px; color:Black;"/></div>
    <div id='show' style="clip:rect(auto   auto   auto   15px); height:400px;"><img src ='' style="width:400px; height:400px;" id="img_Show_ItemID"></div>
    <div><hr  style="width:100%; height:1px; color:Black;"/></div>
    <div id="left"></div>
    <div id="middle">
        <div id="thumblist">
            <asp:Repeater runat="server" ID="Repeater_Images_Item_List">
                <ItemTemplate>                   
                    <div style="clip:rect(auto   auto   auto   15px);">
                       <span><img src ='<%=GetFileHTTPPath %><%#Eval("FileName")%>' style="width:94px; height:93px; cursor:hand;" οnclick="set_txtSelectFileName('<%#Eval("FileName")%>');"></span>
                    </div>
                </ItemTemplate>
            </asp:Repeater>                                                                                                                                                  
        </div>
    </div>
    <div id="right"></div>
    <div>
        <table>
            <tr>
                <td>
                    <asp:FileUpload ID="FileUpload1" runat="server" style="width:240px; height:28px;"/></td>
                <td><input id="butupFile" style="background-image: url(Image/Button.gif);width:95px; height:28px; background-color: transparent;" type="button" value="开始上传" runat="server" onserverclick="butupFile_ServerClick" /></td>
                <td><input id="butDeleteFile" style="background-image: url(Image/Button.gif);width:95px; height:28px; background-color: transparent;" type="button" value="删除选中图片" runat="server" onserverclick="butDeleteFile_ServerClick" /></td>
            </tr>
        </table>
    </div>  
   
</div>
<!--<div>
<input value='聚焦第1张图片' type="button" οnclick="sss(1)" />
<input value='聚焦第2张图片' type="button" οnclick="sss(2)"/>
<input value='聚焦第3张图片' type="button" οnclick="sss(3)"/>
<input value='聚焦第4张图片' type="button" οnclick="sss(4)"/>
<input value='聚焦第5张图片' type="button" οnclick="sss(5)"/>
</div>-->
<script type="text/javascript">


document.all&&document.execCommand("BackgroundImageCache", false, true);

var isIE = (document.all) ? true : false;

var $ = function (id) {
 return  document.getElementById(id);
};

var Extend = function(destination, source) {
 for (var property in source) {
  destination[property] = source[property];
 }
}

var Bind = function(object, fun,args) {
 return function() {
  return fun.apply(object,args||[]);
 }
}

var BindAsEventListener = function(object, fun) {
 var args = Array.prototype.slice.call(arguments).slice(2);
 return function(event) {
  return fun.apply(object, [event || window.event].concat(args));
 }
}

var CurrentStyle = function(element){
 return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}

var Tween = {
    Quart: {
            easeOut: function(t,b,c,d){
                return -c * ((t=t/d-1)*t*t*t - 1) + b;
            }
        }
}

 function create(elm,parent,fn){var element = document.createElement(elm);fn&&fn(element); parent&&parent.appendChild(element);return element};
 function addListener(element,e,fn){ element.addEventListener?element.addEventListener(e,fn,false):element.attachEvent("on" + e,fn)};
 function removeListener(element,e,fn){ element.removeEventListener?element.removeEventListener(e,fn,false):element.detachEvent("on" + e,fn)};

 var Class = function(properties){
       var _class = function(){return (arguments[0] !== null && this.initialize && typeof(this.initialize) == 'function') ? this.initialize.apply(this, arguments) : this;};
       _class.prototype = properties;
       return _class;
 };

var  Imgroll =new Class({
    options:{
        Isrun : false,   //判断是否正在滚动
        Step    : 100,
        Time    : 10,
        t       : 0,
        b       : 0,
        c       : 0,
        d       : 60,
        Tween   : Tween.Quart.easeOut,
        Oninit  : function(){},
        Onstart : function(){},
        Onstop  : function(){}
    },
    initialize:function(show,obj,c,total,i,options){
       try{
        this._show  = show    //代表大图的那个div
        this._obj   = obj;
        this._c     = c;
        this._total = total;
        this.i      = i ;       
        this.o      = '';   //记录图片背景的
        this.timer  = null;
        this.Isrun  = this.options.isrun;
        this.Step   = this.options.Step;
        this.Time   = this.options.Time;
        this.t      = this.options.t;
        this.b      = this.options.b;
        this.c      = this.options.c;
        this.d      = this.options.d;
        this.Tween  = this.options.Tween;   
        this.Oninit = this.options.Oninit;   
        this.Onstart= this.options.Onstart;               
        this.Onstop = this.options.Onstop;
        Extend(this,options||{});
        var self =this, i = 0,img = this._c.getElementsByTagName('div');
        this.o = img[this.i-1];
        this.o.className = "cc";
        for(;i<img.length;i++)
        {
            img[i].num = i;
            (function(i){
             addListener(img[i],'click',Bind(self,self.Start,[img[i]]));
             })(i);
        }
      }catch(e){}
    },
    Start:function(c){
        if(this.Isrun)return;
        this.Isrun = true;
        var img = this._c.getElementsByTagName('div')
        this.b     = this._obj.scrollLeft;
        if(c)
        {   
            /*if(c.num<this.i)
            {
                this.c =  -1*(this.b);
            }
            else if(c.num>img.length-1-this._total+this.i) 
            {
                this.c =(img.length - this._total)*this.Step - this.b
            }
            else
            {
                this.c = (c.num-this.i+1)*this.Step-this.b;
            }*/
            this.c = c.num<this.i?(-1)*this.b:(c.num>img.length-1-this._total+this.i?(img.length - this._total)*this.Step - this.b:(c.num-this.i+1)*this.Step-this.b) 
           
        }

        this.Onstart(c);
        this.Run();
    },
    Run:function(){
        if(this.t<this.d)
        {
            this.RunTo(Math.round(this.Tween(++this.t,this.b,this.c,this.d)))
            this.timer = setTimeout(Bind(this,this.Run),this.Time)
        }
        else
        {
            this.RunTo(this.b+this.c);
            this.Stop();
        }
    },
    RunTo:function(i){
        this._obj.scrollLeft = i;
    },
    Pre:function(){
        this.c = this.Step*(-1);
        this.Start();
    },
    Next:function(){
        this.c = this.Step;
        this.Start();
    },
    Stop:function(){
        clearTimeout(this.timer);
        this.t = 0;this.Isrun=false;
        this.Onstop()
    }
})

var ss = new Imgroll($('show'),$('middle'),$('thumblist'),5,3,{
        Step:109,   //着里的109是指中间每个包含div图片的宽度,也可以写成$('thumblist').getElementsByTagName('div')[0].offsetWidth;
        Onstart:function(obj){
            if(!obj)return;
            ss._show.getElementsByTagName('img')[0].src = obj.getElementsByTagName('img')[0].src;
            this.o.className=''
            this.o=obj;
            obj.className ='cc';
        },
        Onstop:function(){
        $('left').style.backgroundImage=this._obj.scrollLeft == 0?"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453754.p.gif)":"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453879.p.gif)";
        $('right').style.backgroundImage=this._obj.scrollLeft == 545?"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453832.p.gif)":"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453926.p.gif)";
        }});   
    addListener($('right'),'mousedown',function(){ss.Next()});
    addListener($('right'),'mouseover',function(){cbg1(1)});
    addListener($('right'),'mouseout',function(){cbg1(0)});
    addListener($('left'),'mousedown',function(){ss.Pre()});
    addListener($('left'),'mouseover',function(){cbg(1)});
    addListener($('left'),'mouseout',function(){cbg(0)});   
function cbg(n){
    if(ss._obj.scrollLeft==0)return;
    $('left').style.backgroundImage = n?"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453941.p.gif)":"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453879.p.gif)"
}
function cbg1(n){
    if(ss._obj.scrollLeft==545)return;
    $('right').style.backgroundImage = n?"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453957.p.gif)":"url(http://album.hi.csdn.net/app_uploads/wtcsy/20090622/011453926.p.gif)"
}

function sss(num){
    ss.i =num;
}
</script>

<div style="display:none;">
    <asp:TextBox ID="txtSelectFileName" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>

 

 

 

 

 

 

 

 

 

 

===============================后台代码

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

namespace WebFramework.CommonUpFiles
{
    public partial class UpFilesAndPreview : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BinderRepeater();
            }
        }
        /// <summary>
        /// 类别
        /// </summary>
        public string GetTypeName
        {
            get
            {
                return this.Request["Type"];
            }
        }
        /// <summary>
        /// 单据ID
        /// </summary>
        public string GetOrderID
        {
            get {
                return this.Request["ID"];
            }
        }
        /// <summary>
        ///得到网络路径
        /// </summary>
        public string GetFileHTTPPath
        {
            get
            {
                return this.Request.Url.Scheme + "://" + this.Request.Url.Host + "/" + this.Request.Url.AbsolutePath.Split('/')[1] + "/Doc/CommonUpFiles/" + GetOrderID + "/" + GetTypeName + "/";
            }
        }
        /// <summary>
        /// 得到物理路径
        /// </summary>
        public string GetPhysicsPath
        {
            get
            {
                return this.MapPath("../Doc/CommonUpFiles/" + GetOrderID + "/" + GetTypeName + "/");    
            }
        }
        /// <summary>
        /// 绑定显示问题
        /// </summary>
        public void BinderRepeater()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("FileName", typeof(string));

            DirectoryInfo dir = new DirectoryInfo(GetPhysicsPath);
            if (dir.Exists == false)
                dir.Create();

            foreach (FileInfo NextFile in dir.GetFiles())
            {
                DataRow row = dt.NewRow();
                row["FileName"] = NextFile.Name;
                dt.Rows.Add(row);
            }
            this.Repeater_Images_Item_List.DataSource = dt;
            this.Repeater_Images_Item_List.DataBind();

            if (dt.Rows.Count > 0)
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>set_txtSelectFileName('" + dt.Rows[0][0] + "');</script>");
            else
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>set_txtSelectFileName('');</script>");
        }
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butupFile_ServerClick(object sender, EventArgs e)
        {
            try
            {
                FileUpload1.SaveAs(GetPhysicsPath + FileUpload1.FileName);
                BinderRepeater();
            }
            catch (Exception ex)
            {
                Alert(ex.Message);
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butDeleteFile_ServerClick(object sender, EventArgs e)
        {
            try
            {
                File.Delete(GetPhysicsPath + this.txtSelectFileName.Text.Trim());
                BinderRepeater();
            }
            catch (Exception ex)
            {
                Alert(ex.Message);
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本文介绍了Linux平台下的Xwindow图形窗口编程工具GTK,并给出了用GTK编程的基本要素和步骤。 【关键词】GTK,回调函数,消息处理,调节 GTK(GIMP Toolkit)是一个图形用户编程的接口工具。它注册完全免费,所以用来开发自由软件或商业软件都不需要花费什么。现在很多Linux集成系统都已经将GTK1.2版本打包进去了。包括RedHat Linux 6.0以上版本,还有中文化的Turbo Linux等等。它也越来越被普遍的应用于UNIX系统编程。 还有一个组件叫Glib,它包含了一些标准应用的新扩展用来提高GTK的兼容性。用于Linux系统的某些函数可能不适合标准的UNIX系统,例如g_strerror()函数等等。某些函数也扩展了GNUC的一般功能,例如g_malloc函数就有自己加强的调试功能。 GTK可以与多种语言绑定,包括C++, Guile, Perl, Python, Ton, Ada95, Objective C, Free Pascal, Eiffel。用标准C开发的程序,编译软件可用GNU并附带上GTK选项即可。想用除了标准C以外的其它语言来开发Xwindow图形用户程序,则需要先参考一下有关绑定软件的内容(http:// www.gtk.org )。 如果用C++语言来调用GTK进行开发,可以用已经和C++绑定的软件叫GTK--软件,来提供一个比GTK更好的C++编译环境。 目前已经开发出来GTK的增强版GTK+。GTK+是将GTK,GDK,GLIB集成在一起的开发包,可以工作在许多类似于UNIX的系统上,没有GTK的平台限制。 1.GTK的消息处理机制 下面我们先看一个基本的例子,该例子产生一个200×200像素的窗口。它不能自己退出,只能通过shell来杀死进程(调用kill命令)。 /*例子 base.c */ #include <gtk/gtk.h> int main( int argc,char *argv[ ] ){ GtkWidget *window; gtk_init (&argc;, &argv;); /* 初始化显示环境 */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* 创建一个新的窗口*/ gtk_widget_show (window); /*显示窗口*/ gtk_main (); /*进入睡眠状态,等待事件激活*/ return(0); } 从上面的程序可以看出,GTK是一个事件驱动工具包,当它运行到gtk_main()函数时会自动睡眠,直到有事件发生,控制权转让给相应的函数调用,在该函数中可以用标准C写出相应的事物逻辑。这与windows 上的程序处理是一样的。 对窗口对象上发生的事件(如按下鼠标,激活键盘等),GTK也有相应的消息信号产生。这时就需要程序员创建一个信号处理来捕获该信号,并告诉GTK程序事件发生后调用哪个回调函数。信号处理的创建函数定义如下: gint gtk_signal_connect( GtkObject *object, gchar *name,GtkSignalFunc callback_func, gpointer func_data ); 返回值是一个区分同一对象中的事件与不同回调函数的关联标签。这样可以做到一个对象的一个信号就有任意多个回调函数,并且每一个都会按照声明的顺序执行。函数调用的第一个参数是产生信号的widget组件(即按钮等窗口构件),而name则是希望捕获的信号或事件的名称,callback_func则是事件发生后所调用的回调函数名称,而第四个参数func_data则是传递给回调函数的参数。 回调函数要定义在主程序的前面,它们的一般格式都如下所示: void callback_func( GtkWidget *widget, gpointer func_data ); 调用下面这个方法将允许你将回调函数与事件的关联断开: void gtk_signal_disconnect( GtkObject *object, gint id ); 该函数的第二个参数就是上述gtk_signal_connect()函数的返回值,即关联标签。第一个参数指向了去除关联的对象名称。这样可以做到断开事件与回调函数的关联,使得事件发生后,不会调用相关的回调函数。 布局格式 2.1打包盒子 对GTK显示格式的控制是通常通过打包盒子来完成的。widget组件打包可以采用两种方式,水平盒子和垂直盒子。若将widget组件打包进平行盒子,组件就被依次水平的插入窗口;若是垂直盒子,则组件排列是垂直的。产生新的水平盒子的函数为 GtkWidget *gtk_hbox_new (gint homogeneous, gint spacing); 参数homogeneous是用来控制是否盒子中的每个组件都有同样的大小(例如水平盒子中的控件有同样的宽度,垂直盒子中的控件有同样的高度)。Spacing参数是组件之间的间隔。 垂直盒子的创建函数是gtk_vbox_new(),定义与水平盒子一致。 gtk_box_pack_start()和gtk_box_pack_end()函数是用来将打包对象放入这些盒子中的。 void gtk_box_pack_start( GtkBox *box, GtkWidget *child,gint expand, gint fill, gint padding ); 第一个参数是你将组件打进去的盒子指针,第二个参数是你将要打进去的组件指针。Expand参数是用来控制是否允许组件扩展至分配给盒子空间的大小(选TRUE),还是盒子的大小收缩到组件那么大(选FALSE)。函数中的fill参数是用来控制是否将多余的空间分配给组件,即将组件扩展到盒子的大小(选TRUE),或者多余的空间不变,保留作为盒子和打包组件间的间隔。该参数只有在expand参数取TRUE时才有效。Padding参数是指组件四周与盒子的间隔大小。 注意fill取FALSE值,expand取TRUE值时与expand取FALSE值,fill值无效的区别。前者的盒子仍是原来创建盒子时指定的大小,而后者的盒子已经缩小到打包组件的大小了。 gtk_box_pack_end()函数的参数与上面描述的一致。只是排列顺序分别是从下到上 ,从右到左。 最后将所有的盒子或组件打包到一个大盒子中,用gtk_container_add()函数将盒子加入窗口即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值