java圖片處理類(圖片水印,圖片縮放)(3)_JSP教程
推薦:jsp switch語句的用法如果希望選擇執(zhí)行若干代碼塊中的一個,你可以使用switch語句: 語法: switch(n) { case 1: 執(zhí)行代碼塊 1 break case 2: 執(zhí)行代碼塊 2 break default: 如果n即不是1也不是2,則執(zhí)行此代碼 } 工作原理:switch后面的(n)可以是表達(dá)式,也可以(并通常)是變量。然后表達(dá)
/**
* 圖像切割(指定切片的寬度和高度)
* @param srcImageFile 源圖像地址
* @param descDir 切片目標(biāo)文件夾
* @param destWidth 目標(biāo)切片寬度。默認(rèn)200
* @param destHeight 目標(biāo)切片高度。默認(rèn)150
*/
public final static void cut3(String srcImageFile, String descDir,
int destWidth, int destHeight) {
try {
if(destWidth<=0) destWidth = 200; // 切片寬度
if(destHeight<=0) destHeight = 150; // 切片高度
// 讀取源圖像
BufferedImage bi = ImageIO.read(new File(srcImageFile));
int srcWidth = bi.getHeight(); // 源圖寬度
int srcHeight = bi.getWidth(); // 源圖高度
if (srcWidth > destWidth && srcHeight > destHeight) {
Image img;
ImageFilter cropFilter;
Image image = bi.getScaledInstance(srcWidth, srcHeight, Image.SCALE_DEFAULT);
int cols = 0; // 切片橫向數(shù)量
int rows = 0; // 切片縱向數(shù)量
// 計算切片的橫向和縱向數(shù)量
if (srcWidth % destWidth == 0) {
cols = srcWidth / destWidth;
} else {
cols = (int) Math.floor(srcWidth / destWidth) + 1;
}
if (srcHeight % destHeight == 0) {
rows = srcHeight / destHeight;
} else {
rows = (int) Math.floor(srcHeight / destHeight) + 1;
}
// 循環(huán)建立切片
// 改進的想法:是否可用多線程加快切割速度
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
// 四個參數(shù)分別為圖像起點坐標(biāo)和寬高
// 即: CropImageFilter(int x,int y,int width,int height)
cropFilter = new CropImageFilter(j * destWidth, i * destHeight,
destWidth, destHeight);
img = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(image.getSource(),
cropFilter));
BufferedImage tag = new BufferedImage(destWidth,
destHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(img, 0, 0, null); // 繪制縮小后的圖
g.dispose();
// 輸出為文件
ImageIO.write(tag, "JPEG", new File(descDir
+ "_r" + i + "_c" + j + ".jpg"));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
分享:jsp if else語句使用方法if else在大部份編程語言中都是這樣使用的,我們今天來簡單的介紹一下關(guān)于jsp教程 中的if else 與多重條件判斷。 HTML HEAD TITLEUsing the if Statement/TITLE /HEAD BODY H1Using the if Statement/H1 % int value = 10; if(value 0) out.println(Absolute value of
- jsp response.sendRedirect不跳轉(zhuǎn)的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復(fù)習(xí)整理
- JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例
- JSP FusionCharts Free顯示圖表 具體實現(xiàn)
- 網(wǎng)頁模板:關(guān)于jsp頁面使用jstl的異常分析
- JSP頁面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項目中連接Access數(shù)據(jù)庫的配置方法
- JDBC連接Access數(shù)據(jù)庫的幾種方式介紹
- 網(wǎng)站圖片路徑的問題:絕對路徑/虛擬路徑
- (jsp/html)網(wǎng)頁上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對路徑下的圖片解決方法
JSP教程Rss訂閱編程教程搜索
JSP教程推薦
猜你也喜歡看這些
- 講解Linux系統(tǒng)下JDK、Tomcat的安裝
- jsp頁面中顯示word/excel格式的文檔的方法
- 使用靜態(tài)類實現(xiàn)JSP自定義標(biāo)簽
- 檢測輸入的字符是否為0-9的數(shù)字(測試)
- java中cookie操作詳細(xì)
- javascript通過url向jsp頁面?zhèn)鬟f中文參數(shù)導(dǎo)致亂碼解決方案
- JSP頁面緩存cache技術(shù)--瀏覽器緩存介紹及實現(xiàn)方法
- JSP Filter的應(yīng)用方法
- jsp 內(nèi)嵌網(wǎng)頁內(nèi)容--iframe
- J2ME編程中三種低級用戶界面事件處理技術(shù)
- 相關(guān)鏈接:
- 教程說明:
JSP教程-java圖片處理類(圖片水印,圖片縮放)(3)
。