導航:首頁 > 編程語言 > extjs圖片預覽

extjs圖片預覽

發布時間:2023-07-07 18:12:49

『壹』 extjs 3.4中 怎麼給htmlEdit添加圖片插件 實現圖片上傳功能

首先要使用extjs自帶的HTMLEditor,然後在原有的工具條上添加一個圖片按鈕,點擊這個圖片按鈕要彈出窗口,這個窗口負責實現上傳功能,實現上傳後,要將上傳的圖片路徑添加到HTMLEditor的游標處,並且要以<IMG></IMG>的方式,這樣HTMLEditor才能解析出來。實現代碼如下:

前台JSP頁面



fieldLabel : '商品特性',
id : 'shopSp.spTxms',

name : 'shopSp.spTxms',
xtype : 'StarHtmleditor',
anchor : '93%'


這其中引用了StarHtmleditor,StarHtmleditor.js的代碼如下,直接將代碼復制下來,然後新建個JS,全復制進去就行了。


var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, {
addImage : function() {
var editor = this;
var imgform = new Ext.FormPanel({
region : 'center',
labelWidth : 55,
frame : true,
bodyStyle : 'padding:5px 5px 0',
autoScroll : true,
border : false,
fileUpload : true,
items : [{
xtype : 'textfield',
fieldLabel : '選擇文件',
id : 'UserFile',
name : 'UserFile',
inputType : 'file',
allowBlank : false,
blankText : '文件不能為空',
anchor : '90%'
}],
buttons : [{
text : '上傳',
handler : function() {
if (!imgform.form.isValid()) {return;}
imgform.form.submit({
waitMsg : '正在上傳......',
url : 'HTMLEditorAddImgCommonAction.action',
success : function(form, action) {
var element = document.createElement("img");
element.src = action.result.fileURL;
if (Ext.isIE) {
editor.insertAtCursor(element.outerHTML);
} else {
var selection = editor.win.getSelection();
if (!selection.isCollapsed) {
selection.deleteFromDocument();
}
selection.getRangeAt(0).insertNode(element);
}
//win.hide();//原始方法,但只能傳一個圖片
//更新後的方法
form.reset();
win.close();
},
failure : function(form, action) {
form.reset();
if (action.failureType == Ext.form.Action.SERVER_INVALID)
Ext.MessageBox.alert('警告','上傳失敗',action.result.errors.msg);
}
});
}
}, {
text : '關閉',
handler : function() {
win.close(this);
}
}]
})

var win = new Ext.Window({
title : "上傳圖片",
width : 300,
height : 200,
modal : true,
border : false,
iconCls : "picture.png",
layout : "fit",
items : imgform

});
win.show();
},
createToolbar : function(editor) {
HTMLEditor.superclass.createToolbar.call(this, editor);
this.tb.insertButton(16, {
cls : "x-btn-icon",
icon : "picture.png",
handler : this.addImage,
scope : this
});
}
});
Ext.reg('StarHtmleditor', HTMLEditor);

JS的第一句var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, 網上是沒有var的,不用var不知道為什麼總是報錯,另外JS一定要與JSP的編碼方式一致,要不然報莫名其妙的錯誤,而且錯誤都沒有顯示。

後台java代碼



/****
* HTMLEditor增加上傳圖片功能:
* 1、上傳圖片後,需要將圖片的位置及圖片的名稱返回給前台HTMLEditor
* 2、前台HTMLEditor根據返回的值將圖片顯示出來
* 3、進行統一保存
* @param 上傳圖片功能
* @return JSON結果
* @throws IOException
*/
public void HTMLEditorAddImg() throws IOException {
if(!"".equals(UserFile) && UserFile != null && UserFile.length() > 0){
File path = ImportImg(UserFile, "jpg");
UserFilePath = "../" + path.toString().replaceAll("\\", "/").substring(path.toString().replaceAll("\\", "/").indexOf("FileImg"));
}
this.getResponse().setContentType("text/html");
this.getResponse().getWriter().write("{success:'true',fileURL:'" + UserFilePath + "'}");
}


特別要注意的是路徑問題,路徑問題主要有2點需要注意:

1、前台頁面引用StarHtmleditor.js的路徑一定要正確;

2、Htmleditor上傳的圖片路徑一定要改,因為上傳之後圖片路徑變為http://localhost:8080/,在正常使用中圖片不顯示,要將該地址替換為伺服器的IP地址;替換方法如下:


//獲取本地IP地址,因為extjs的htmleditor上傳的照片路徑有問題,需要將路徑替換為本機IP地址
InetAddress inet = InetAddress.getLocalHost();
shopSp.setSpTxms(shopSp.getSpTxms().replace("localhost", inet.getHostAddress().toString()));

這樣基本就完成了這個HTMLEditor上傳圖片功能。

如圖:

『貳』 extjs實現顯示圖片,請給出詳細步驟,最好是代碼。謝謝

用grid提供的事件
這是進入item的事件
itemmouseenter( this, record, item, index, e, eOpts )
這是離開item的事件
itemmouseleave( this, record, item, index, e, eOpts )

進入顯示專圖片panel
離開隱藏屬

『叄』 Extjs grid列里怎麼顯示圖片

Ext.onReady(function(){
varcm=newExt.grid.ColumnModel([newExt.grid.RowNumberer(),{
header:'編號',
dataIndex:'id',
sortable:true
},{
header:'性別',
dataIndex:'sex',
renderer:function(value){
if(value=='male'){
return"<spanstyle='color:green;font-weight:bold;'>綠男</span><imgsrc='user_male.gif'/>";
}else{
return"<spanstyle='color:red;font-weight:bold;'>紅女</span><imgsrc='user_female.gif'/>";
}
},
sortable:true
},{
header:'名稱',
dataIndex:'name',
align:"center",
sortable:true
}]);
vardata=[['1','male','name1','descn1'],
['2','female','name2','descn2'],
['3','male','name3','descn3'],
['4','female','name4','descn4'],
['5','male','name5','descn5'],
['6','female','name6','descn6']];
vards=newExt.data.Store({
proxy:newExt.data.MemoryProxy(data),
reader:newExt.data.ArrayReader({},[
{
name:'id'
},//{name:'id',mapping:1},
{
name:'sex'
},{
name:'name'
},{
name:'descn'
}])
});
ds.load();
vargrid=newExt.grid.GridPanel({
title:'GridPanel',
id:'view_grid',
renderTo:'grid',
ds:ds,
cm:cm,
width:400,
autoHeight:true,
autoWidth:true,
enableColumnMove:false,
autoSizeColumns:true,//根據每一列內容的寬度自適應列的大小
trackMouseOver:true,//滑鼠移動時高亮顯示
frame:true,
selModel:newExt.grid.RowSelectionModel({
singleSelect:true
}),
iconCls:'icon-grid'
});
});

如圖所示,圖片是綠色和紅色的人,根據值,判斷顯示什麼顏色的。你可以改成根據0或1顯示或不顯示圖片。

『肆』 extjs中如何顯示圖片列表

EXTJS中顯示圖片方法
userInfoForm.superclass.constructor.call(this, {
bodyStyle: 'padding:10px 10px 10px',
width:250,
region:'west',
closeAction:'true',
title:'個人信息',
buttonAlign:'center',
items:[
{xtype:'panel',
width : 200,
Height : 160,
border:false,
html:'<img src="qing.jpg">'}, 可以顯示
{xtype : 'textfield',
fieldLabel : '個人照片',
width : 150,
Height : 180,
inputType : 'image',
fieldLabel :'笑臉豆豆<font color=red>*</font>',
anchor:'97%',
listeners : { // 該項被載入時載入照片
'render' : function(_filed) {
_filed.getEl().dom.src = "qing.jpg";//這里圖片的路徑可以預先從store中讀取,賦給變數然後給它
} //動態顯示圖片
}
},{

xtype : 'box',
id : 'browseImage',
fieldLabel : "用戶頭像",
autoEl : {
width : 300,
height : 350,
tag : 'img',
// type : 'image',
src : Ext.BLANK_IMAGE_URL,
style : 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);',
complete : 'off',
id : 'imageBrowse'
}
}
]
});
}
Ext.extend(userInfoForm ,Ext.form.FormPanel,{
});

『伍』 extjs怎樣做圖片上傳

1.代碼如下:
復制代碼
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <!--ExtJs框架開始-->
6 <script type="text/javascript" src="/Ext/adapter/ext/ext-base.js"></script>
7 <script type="text/javascript" src="/Ext/ext-all.js"></script>
8 <script src="/Ext/src/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
9 <link rel="stylesheet" type="text/css" href="/Ext/resources/css/ext-all.css" />
10 <!--ExtJs框架結束-->
11 <script type="text/javascript">
12 Ext.onReady(function () {
13 //初始化標簽中的Ext:Qtip屬性。
14 Ext.QuickTips.init();
15 Ext.form.Field.prototype.msgTarget = 'side';
16 //創建div組件
17 var imagebox = new Ext.BoxComponent({
18 autoEl: {
19 style: 'width:150px;height:150px;margin:0px auto;border:1px solid #ccc; text-align:center;padding-top:20px;margin-bottom:10px',
20 tag: 'div',
21 id: 'imageshow',
22 html: '暫無圖片'
23 }
24 });
25 //創建文本上傳域
26 var file = new Ext.form.TextField({
27 name: 'imgFile',
28 fieldLabel: '文件上傳',
29 inputType: 'file',
30 allowBlank: false,
31 blankText: '請瀏覽圖片'
32 });
33 //提交按鈕處理方法
34 var btnsubmitclick = function () {
35 if (form.getForm().isValid()) {
36 form.getForm().submit({
37 waitTitle: "請稍候",
38 waitMsg: '正在上傳...',
39 success: function (form, action) {
40 Ext.MessageBox.alert("提示", "上傳成功!");
41 document.getElementById('imageshow').innerHTML = '<img style="width:150px;height:150px" src="' + action.result.path + '"/>';
42 },
43 failure: function () {
44 Ext.MessageBox.alert("提示", "上傳失敗!");
45 }
46 });
47 }
48 }
49 //重置按鈕"點擊時"處理方法
50 var btnresetclick = function () {
51 form.getForm().reset();
52 }
53 //表單
54 var form = new Ext.form.FormPanel({
55 frame: true,
56 fileUpload: true,
57 url: '/App_Ashx/Demo/Upload.ashx',
58 title: '表單標題',
59 style: 'margin:10px',
60 items: [imagebox, file],
61 buttons: [{
62 text: '保存',
63 handler: btnsubmitclick
64 }, {
65 text: '重置',
66 handler: btnresetclick
67 }]
68 });
69 //窗體
70 var win = new Ext.Window({
71 title: '窗口',
72 width: 476,
73 height: 374,
74 resizable: true,
75 modal: true,
76 closable: true,
77 maximizable: true,
78 minimizable: true,
79 buttonAlign: 'center',
80 items: form
81 });
82 win.show();
83 });
84 </script>
85 </head>
86 <body>
87 <!--
88 說明:
89 (1)var imagebox = new Ext.BoxComponent():創建一個新的html標記。
90 官方解釋如下:
91 This may then be added to a Container as a child item.
92 To create a BoxComponent based around a HTML element to be created at render time, use the autoEl config option which takes the form of a DomHelper specification:
93 (2) autoEl: {style: '',tag: 'div',id: 'imageshow', html: '暫無圖片'}定義這個html標記的屬性,如 標記為:div,id是多少等。
94 官方實例為:
95 var myImage = new Ext.BoxComponent({
96 autoEl: {
97 tag: 'img',
98 src: '/images/my-image.jpg'
99 }
100 });
101 (3)var file = new Ext.form.TextField():創建一個新的文件上傳域。
102 (4)name: 'imgFile':名稱,重要,因為service端要根據這個名稱接收圖片。
103 (5)inputType: 'file':表單類型為文件類型。
104 (6)waitTitle: "請稍候",waitMsg: '正在上傳...',:上傳等待過程中的提示信息。
105 (7)document.getElementById('imageshow').innerHTML = '<img style="width:150px;height:150px" src="' + action.result.path + '"/>';這個是原生態的js,把imageshow的值換成圖片。
106 -->
107 </body>
108 </html>
復制代碼
其中與service交互用上傳圖片的 一般處理程序文件,源碼如下:
/App_Ashx/Demo/Upload.ashx
復制代碼
1 using System;
2 using System.Web;
3 using System.IO;
4 using System.Globalization;
5
6 namespace HZYT.ExtJs.WebSite.App_Ashx.Demo
7 {
8 public class Upload : IHttpHandler
9 {
10 public void ProcessRequest(HttpContext context)
11 {
12 //虛擬目錄,建議寫在配置文件中
13 String strPath = "/Upload/Image/";
14 //文件本地目錄
15 String dirPath = context.Server.MapPath(strPath);
16 //接收文件
17 HttpPostedFile imgFile = context.Request.Files["imgFile"];
18 //取出文件擴展名
19 String fileExt = Path.GetExtension(imgFile.FileName).ToLower();
20 //重新命名文件
21 String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
22 //文件上傳路徑
23 String filePath = dirPath + newFileName;
24 //保存文件
25 imgFile.SaveAs(filePath);
26 //客戶端輸出
27 context.Response.Write("{success:true,path:'" + strPath + newFileName + "'}");
28 }
29
30 public bool IsReusable
31 {
32 get
33 {
34 return false;
35 }
36 }
37 }
38 }
復制代碼
2.效果如下:
無廢話extjs
3.說明:
(1)上傳域不光可以上傳圖片,還要以上傳其他文件。這里我們以圖片為例。
(2)在實際開發中,我們還要對圖片格式,大小等進行校驗,這個示例測重於上傳,沒有加入任何校驗。

『陸』 extjs怎麼使圖片上傳時顯示預覽

這個我做過,不難,思路給你 1.是當文本框內容發生改變的時候就將圖片上傳到伺服器(如果圖片小,用戶是感覺不到你已經做了上傳操作的。) 2.當伺服器接受到這個圖片的時候,將其放入到一個臨時文件夾中並返回給前台一個圖片路徑(圖片流也可以)。 3.Ajax請求會有一個相應,在伺服器端成功接受到上傳的圖片後,返回給Ajax一個Reponse,這個Reponse里包含一個圖片路徑。 4.ExtJS在前台獲取success里的responseText之後(也就是圖片路徑)將默認圖片的src指向從後台反饋回來的圖片路徑。 現在圖片就會現實出來流程是:用戶選擇圖片--> 觸發文本框改變事件---> 在事件中通過AJAX將圖片上傳給伺服器---> 伺服器將圖片名稱修改為UUID以免重復,並將此圖片的路徑返回給前台---> 前台AJAX請求的回調函數中獲取responseText,也就是圖片路徑---> 設置默認圖片的src為responseText----> 用戶重新選擇的時候(例如用戶不喜歡這張圖)---> 在文本框改變事件中通過AJAX將圖片上傳(包括先前上傳的圖片名稱)---> 後台根據參數先刪除臨時圖片---> 重復以上的步驟直到用戶確定 需要注意的問題: 1.當用戶改變了圖片之後,需要把上一次的臨時圖片文件刪除掉,以免出現垃圾圖片過多。 2.每次上傳圖片的時候要在後面跟上一個隨機參數(因為如果請求路徑和參數相同,瀏覽器不會再繼續發送請求)。通常情況下使用new Date()就可以了例如 "uploadImag.do?method=uploadImage&randomParam="+new Date() 3.圖片太大的話,效果不是很好。 4.當用戶點擊確定後,將臨時文件里的圖片放置到你的正式圖片存放目錄下即可。

『柒』 Extjs圖片顯示的問題

你路徑寫錯了
你用的框架應該是play或者maven吧
對於框架來說,你的根目錄其實原本就是src/main/webapp
你alert出來的地址代表系統找圖片時的地址是src/main/webapp/src/main/webapp,下面肯定沒有個這個目錄
你控制台訪問也是提示找不到圖片,你可以復制那個找不到的地址,然後把其中的src/main/webapp這個路徑刪除,在瀏覽器里看能不能找到圖片
我覺得你應該是理解錯了項目的根目錄,其實你localhost:8080/sale-web/就已經是在你項目的src/main/webapp這個目錄下了,你可以試試
希望能幫助到你

『捌』 extJs XTemplate,DataView,顯示資料庫中的圖片

由於不清楚你使用的語言,因此介紹下我用的方法:
1.建一頁面,從資料庫中讀取blob圖片,假設為img.asp;之後,img.asp頁面可以視為圖片對象來調用;
<%
sql = "select * from 表名"
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = 3
oRS.Open sql, "DSN=NW"
SetImageForDisplay oRS("欄位名"), "ole"
Set oRS.ActiveConnection = Nothing
%>

2.調用,以html為例說明下:<img src="img.asp"></img>,注意文件路徑;

上述,關鍵的地方在於,img.asp可能會因為需求不同而生成不同的圖片,由於緩存的原因,每次調用img.asp實際上會是同一張圖片,但我們又不可能為每張圖片設置單獨頁面。這里推薦使用在img.asp之後使用附加參數來解決,如img.asp?id=1,即:<img src="img.asp?id=1"></img>,只需在img.asp頁面處理id參數即可。
<%
sql = "select * from 表名 where id=1"
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = 3
oRS.Open sql, "DSN=NW"
SetImageForDisplay oRS("欄位名"), "ole"
Set oRS.ActiveConnection = Nothing
%>

『玖』 extjs 4.2.3 放大縮小是由什麼控制

extjs 4.2.3 放大縮小實現方法:繼承ext.panel實現自己的圖片預覽類imagePreview即可。
imagePreview.js源碼:
afterRender : function() {
ImgView.superclass.afterRender.call(this);
Ext.get(this.img_view_id).parent = this;
Ext.get(this.img_view_id).center();
new Ext.dd.DD(Ext.get(this.img_view_id), 'pic');
Ext.get(this.img_view_id).dom.title = '滑鼠滾輪控制圖片的放大和縮小';
Ext.get(this.img_view_id).on({
'dblclick' : {
fn : function() {
Ext.get(this).parent.zoom(Ext.get(this), 1.5, true);
}
},
'mousewheel' : {
fn : function(e) {
var delta = e.getWheelDelta();
if (delta > 0) {
Ext.get(this).parent.zoom(Ext.get(this), 1.5,
true);
} else {
Ext.get(this).parent.zoom(Ext.get(this), 1.5,
false);
}

}
}
});
},
/**
* 圖片放大和縮小
*
* @param {}
* el 一個dom對象
* @param {}
* offset 放大或者縮小的偏移量
* @param {}
* type true為放大,false為縮小
*/
zoom : function(el, offset, type) {
var width = el.getWidth();
var height = el.getHeight();
var nwidth = type ? (width * offset) : (width / offset);
var nheight = type ? (height * offset) : (height / offset);
var left = type ? -((nwidth - width) / 2) : ((width - nwidth) / 2);
var top = type ? -((nheight - height) / 2) : ((height - nheight) / 2);
el.animate({
height : {
to : nheight,
from : height
},
width : {
to : nwidth,
from : width
},
left : {
by : left
},
top : {
by : top
}
}, null, null, 'backBoth', 'motion');
}
});
使用該類進行調用擴大和縮小:
image.js:
Ext.onReady(function() {
var img1 = new ImgView({
src : ['images/preview/001.jpg',
"images/preview/002.jpg",
'images/preview/003.jpg',
"images/preview/004.jpg",
'images/preview/005.jpg',
"images/preview/006.jpg",
'images/preview/007.jpg',
"images/preview/008.jpg"],
title : '圖片瀏覽'
});
// alert(img1.img_index);
var main_panel = new Ext.Panel({
title : '圖片預覽',
el : 'main_panel',
autoHeight : true,
bodyBorder : false,
collapsible : true,
renderTo : Ext.getBody(),
items : [img1]
});
});

閱讀全文

與extjs圖片預覽相關的資料

熱點內容
網路評選一般有哪些 瀏覽:476
2021三支一扶報名數據在哪裡看 瀏覽:914
網路未備案怎麼打得開 瀏覽:987
計算機程序用什麼編程語言 瀏覽:324
linux入門常用命令 瀏覽:497
江寧區哪裡有數控編程培訓 瀏覽:778
java寫一個shape形狀類 瀏覽:744
win7如何設置word背景顏色 瀏覽:484
如何創造電腦編程語言 瀏覽:56
昂達平板電腦圖形密碼忘記怎麼辦 瀏覽:92
組織文件內容是什麼 瀏覽:183
0基礎如何學習智能編程 瀏覽:366
java程序員全攻略下載 瀏覽:715
網路逆向教程 瀏覽:135
iso文件如何重裝系統 瀏覽:750
ghost鏡像文件路徑如何恢復 瀏覽:832
搭建網站需要多少錢啊 瀏覽:599
編程貓怎麼設置背景亮度 瀏覽:177
qq文件破損 瀏覽:414
javapoi配置 瀏覽:608

友情鏈接