<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">就直接贴代码了,我是直接把项目代码拷过来,有很多与本主题无关的干扰代码,看着可能比较费劲,以后有空再整理了</span>
1.jsp页面
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ page language="java" import="java.util.*,java.net.URL"
pageEncoding="utf-8"%>
<%
String contextPath = request.getContextPath();
%>
<script type="text/javascript" src="/portal/resources/js/jquery.Jcrop.min.js"></script>
<link href="<%=contextPath%>/resources/css/jquery.Jcrop.min.css" rel="stylesheet" type="text/css" />
<style type="text/css">
/* The Javascript code will set the aspect ratio of the crop
area based on the size of the thumbnail preview,
specified here */
#preview-pane .preview-container {
width: 250px;
height: 250px;
overflow: hidden;
}
</style>
<script type="text/javascript">
//添加内卡Input
function addShopCard(){
var $cardLen=$("input[name='shopCard']").length;
if($cardLen>10){
return
}
var cardHtml = "<div class='line20'></div>"+
"<nobr><span class='width_100'> </span>"+
" <input type='text' name='shopCard' class='inputmend' maxlength='20' placeholder='请输入内卡'/> "+
"<img οnclick='delShopCard(this)' height='30px' width='30px' src='<%=contextPath%>/resources/images/round_del.jpg' title='删除'/>"+
"</nobr>";
$("#afterCar").before(cardHtml);
}
//删除内卡Input
function delShopCard(obj){
$(obj).parent().prev().remove();
$(obj).parent().empty();
}
$(function() {
$('#fileUp').change(function() {
$('#uploadLog').html('开始上传中....');
$('#formFile').submit();
});
})
function uploadSuccess(msg) {
if (msg.split('|').length > 1) {
var url= "/portal/upload/"+msg.split('|')[1];
$('#preview').attr('src', url);
$('#target').attr('src', url);
$('#filePath').val(url);
cutImage();
$(".jcrop-holder").find("img").attr("src",url);
$('#uploadLog').html(msg.split('|')[0]);
// alert(msg.split('|')[0]);
} else {
$('#uploadLog').html(msg);
// alert(msg);
}
}
var x;
var y;
var width;
var height;
function cutImage(){
var jcrop_api,
boundx,
boundy,
$pcnt = $('#preview-pane .preview-container'),
xsize = $pcnt.width(),
ysize = $pcnt.height();;
$('#target').Jcrop({
onChange: updatePreview,
onSelect: updatePreview,
aspectRatio: xsize / ysize
},function(){
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
// Store the API in the jcrop_api variable
jcrop_api = this;
});
function updatePreview(c){
if (parseInt(c.w) > 0){
var rx = xsize / c.w;//预览窗口宽占裁剪宽
var ry = ysize / c.h;
$('#preview').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
$('#desWidth').val(Math.round(rx * boundx)); //放大后的宽
$('#desHeight').val(Math.round(ry * boundy)); //放大后的高
$('#width').val(xsize); //c.w 裁剪区域的宽
$('#height').val(ysize); //c.h 裁剪区域的高
$('#x').val(Math.round(rx * c.x)); //c.x 裁剪区域左上角顶点相对于图片左上角顶点的x坐标
$('#y').val(Math.round(ry * c.y)); //c.y 裁剪区域顶点的y坐标</span>
}
};
}
$(function(){
});
function saveCompanyShop(){
if ($("#shopName").val() == "") {
alert("请填写门店名称");
return;
} else if ($("#shopStoreId").val() == "") {
alert("请填写机构编码");
return;
}
if(/^[A-Za-z0-9]+$/.test($("#shopStoreId").val())==false){
alert("机构编号仅限英文和数字");
return;
}
if ($("#shopName").val().length>100) {
alert("门店名称不可超过100个字符");
return;
}
var $card = $("input[name='shopCard']");
var chopCardVal="";
for(var i=0;i<$card.length;i++){
chopCardVal+=$card[i].value+",";
}
var param={};
param['shopName']=$("#shopName").val();
param['shopCard']=chopCardVal;
param['shopTel']=$("#shopTel").val();
param['brandId']=$("#brandId").val();
param['shopProvince']=$("#s_province").val();
param['shopCity']=$("#s_city").val();
//param['shopArea']=$("#district").val();
param['shopAddress']=$("#shopAddress").val();
param['parentOrganizationId']=$("#parentOrganizationId").val();
param['shopStoreId']=$("#shopStoreId").val();
param['wxOriginalId']=$("#wxOriginalId").val();
param['imageX']=$("#x").val();
param['imageY']=$("#y").val();
param['imageWidth']=$("#width").val();
param['imageHeight']=$("#height").val();
param['filePath']=$("#filePath").val();
param['desHeight']=$("#desHeight").val();
param['desWidth']=$("#desWidth").val();
//alert($("#filePath").val());
$(function(){
$.post("<%=contextPath %>/web_shop_controllers/add_company_shop.do",param,function(data){
if(data=="success"){
alert("创建门店成功!");
$('#member_content').load("/portal/web_shop_controllers/view_company_shop.do");
}else{
alert(data);
}
});
});
}
$("#cancelBtn").click(function(){
$('#member_content').load("/portal/web_shop_controllers/view_company_shop.do");
});
/*下拉列表框*/
$(function(){
//省市联级初始化
_init_area();
});
function selectBrand(organizationId){
var param={};
param['organizationId']= organizationId.value;
$.post("<%=contextPath %>/web_shop_controllers/list_organization.do",param,function(data){
var myobj=eval(data);
var optionString="";
for(var i=0;i<myobj.length;i++){
optionString += "<option value='"+myobj[i].organizationId+"'>"+myobj[i].name+"</option>"
}
$("#parentOrganizationId").html(optionString);
});
}
</script>
<!--右边内容-->
<div class="conright">
<div class="conmenu">
<span class="color-fs">当前位置 <img src="<%=contextPath%>/resources/weixin/images/menu_t2.png" /> <a href="#" οnclick="$('#member_content').load('/portal/web_shop_controllers/view_company_shop.do');">门店信息 </a></span> <img src="<%=contextPath%>/resources/weixin/images/menu_t2.png" /> 创建门店
</div>
<div class="searchbox">
<div class="selectinfo" style="overflow: hidden; border-bottom:none;padding-left:30px; width:975px; padding-top:30px; position:relative">
<!--左边表单-->
<div class="leftInput">
<input type="hidden" name="imageX" id="x"/>
<input type="hidden" name="imageY" id="y"/>
<input type="hidden" name="imageWidth" id="width"/>
<input type="hidden" name="imageHeight" id="height"/>
<input type="hidden" name="desHeight" id="desHeight"/>
<input type="hidden" name="desWidth" id="desWidth"/>
<input type="hidden" name="filePath" id="filePath"/>
<span class="width_100">所属品牌:</span>
<select οnchange="selectBrand(this)" id="brandId" name="brandId" style="width: 330px;">
<option value="">请选择</option>
<c:forEach var="organization" items="${orgList}" varStatus="status">
<option value="${organization.organizationId}">${organization.name}</option>
</c:forEach>
</select>
<div class="line20"></div>
<span class="width_100">门店名称:</span>
<input type="text" name="shopName" id="shopName" value="" class="inputmend" /><span id="loginName_info" style="color: red">*</span>
<div class="line20"></div>
<nobr>
<span class="width_100">内卡:</span>
<input type="text" name="shopCard" id="shopCard" class="inputmend" maxlength="50" /><br>
<div class="line20"></div><span class="width_100"> </span> <input type="text" name="shopCard" id="shopCard" class="inputmend" maxlength="50" />
<div class="line20"></div><span class="width_100"> </span> <input type="text" name="shopCard" id="shopCard" class="inputmend" maxlength="50" />
<img οnclick="addShopCard()" height="30px" width="30px" src="<%=contextPath%>/resources/images/round_add.png" title="点击添加一张内卡"/>
</nobr>
<div class="line20" id="afterCar"></div>
<span class="width_100">门店电话:</span>
<input type="text" id="shopTel" id="shopTel" class="inputmend" />
<div class="line20"></div>
<span class="width_100">所在地:</span><select id="s_province" name="s_province" style="width:140px; min-width:140px;" ></select>
<select id="s_city" name="s_city" ></select>
<!--
<div class="line20"></div>
<span class="width_100">所属区/县:</span>--><select id="s_county" hidden="true" name="s_county" ></select><select hidden="true" id="fid" name="fid" class="width_110"><option></option></select>
<div class="line20"></div>
<input type="text" style="margin-left:104px;" id="shopAddress" class="inputmend" placeholder="具体地址" maxlength="500"/>
<div class="line20"></div>
<span class="width_100">父级机构:</span>
<select id="parentOrganizationId" style="width: 330px;">
<c:forEach var="organization" items="${companyOrganization}"
varStatus="status">
<option value="${organization.organizationId}">${organization.name}</option>
</c:forEach>
</select>
<div class="line20"></div>
<span class="width_100">机构编号: </span>
<input type="text" name="shopStoreId" id="shopStoreId" value="" class="inputmend" maxlength="44"/> <span id="loginName_info" style="color: red">*</span>
<p style="padding:9px 0px 5px 100px; color:#CCC">机构名称:</p>
<span class="width_100">虚拟原始ID:</span>
<select id="wxOriginalId">
<c:forEach var="info" items="${numberInfo}" varStatus="status">
<option value="${info.originalId}">${info.name}</option>
</c:forEach>
</select>
</div>
<iframe id='frameFile' name='frameFile' style='display: none;'></iframe>
<div class="rightUpload">
<div>
<img src="<%=contextPath%>/resources/images/demo_pic.jpg" id="target" style="width:380px;"/>
<div class="line15"></div>
<div style="position:relative;">
<form id='formFile' name='formFile' method="post" action="/portal/web_shop_controllers/upload_shop_image.do" target='frameFile' enctype="multipart/form-data">
<a href="#" class="btn btn-danger" style="float:left; margin-right:5px; padding:8px 45px;width:180px;"><img src="<%=contextPath%>/resources/images/upload_01.png" /> 上传图片</a> <a href="#" class="btn btn-default" style="float:left; padding:8px 45px;width:180px;"><img src="<%=contextPath%>/resources/images/delete_01.png" /> 删 除</a>
<input type='file' id='fileUp' name='fileUp' style="position:absolute; top:0; height:42px;filter:alpha(opacity:0);opacity: 0;width:175px"/>
</form>
</div>
</div>
<div class="line15"></div>
<p style="font-size:12px; color:#CCC; clear:both; padding:5px 0px" >(最多上传1M,支持 png、jpg、gif 图片格式)<span id="uploadLog"></span></p> 预览:
<div id="preview-pane" style="margin-left:70px;">
<div class="preview-container" >
<img src="<%=contextPath%>/resources/images/demo_pic.jpg" class="jcrop-preview" alt="Preview" id="preview" />
</div>
</div>
</div>
</div>
</div>
<div style="text-align:center; padding-top:20px;">
<a href="javascript:;" id="cancelBtn" class="btn btn-default" style="padding: 8px 40px;">取 消 </a>
<a href="javascript:saveCompanyShop();" class="btn btn-success" style="padding:8px 40px;">保 存 </a>
</div>
</div>
<!--右边内容结束-->
2.后台Spring mvc Controller,上传图片
@RequestMapping(value = "/upload_shop_image")
@ResponseBody
public void uploadImage(HttpServletRequest request,HttpServletResponse response){
List<String> fileTypes = new ArrayList<String>();
fileTypes.add("jpg");
fileTypes.add("jpeg");
fileTypes.add("png");
fileTypes.add("gif");
PrintWriter out = null;;
try {
out = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//转型为MultipartHttpRequest
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获得第1张图片(根据前台的name名称得到上传的文件)
MultipartFile imgFile1 = multipartRequest.getFile("fileUp");
if(imgFile1.getSize()/(1024*1024)>1){
out.write("<script>window.parent.uploadSuccess('上传失败,文件大于1M!')</script>;");
return;
};
//保存第一张图片
final String basePath = request.getSession().getServletContext().getRealPath("/upload");
if(!(imgFile1.getOriginalFilename() ==null || "".equals(imgFile1.getOriginalFilename()))) {
String fileName = imgFile1.getOriginalFilename();
String ext = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length()).toLowerCase();
if(fileTypes.contains(ext)) { //如果扩展名属于允许上传的类型,则创建文件
try {
String realfileName = UUID.randomUUID().toString()+"."+ext;
//将图片缩放成600*600并保存
ImgUtil.createThumb(imgFile1.getBytes(), basePath+"/"+realfileName, 600, 600);
out.write("<script>window.parent.uploadSuccess('上传成功!|"+realfileName+"');</script>");
} catch (Exception e) {
e.printStackTrace();
out.write("<script>window.parent.uploadSuccess('上传失败!');</script>");
return;
}
} else{
out.write("<script>window.parent.uploadSuccess('您上传的文件格式不正确!上传格式有.gif.jpg.png.bmp')</script>;");
return;
}
}
out.flush();
out.close();
if(basePath.trim().equals(""))
return;
//十分钟后清除上传的图片缓存
new Timer().schedule(new TimerTask() {
@Override
public void run() {
File f = new File(basePath);
if(f.exists()){
f.delete();
}
}
}, 1000*60*10);
}
3.裁剪并保存
@RequestMapping(value = "/add_company_shop", method = RequestMethod.POST)
public void addCompanyShop(CompanyShop companyShop,
String parentOrganizationId, HttpServletRequest request, HttpServletResponse response,
String imageX,String imageY,String imageWidth,String imageHeight,String filePath,String desWidth,String desHeight) {
response.setContentType("application/text");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
return;
}
String province = companyShop.getShopProvince();
String city = companyShop.getShopCity();
if(province != null&& !province.trim().equals("")){
province = "省份".equals(province) ? "" : province;
}
if(city != null&& !city.trim().equals("")){
city = "城市".equals(city) ? "" : city;
}
companyShop.setShopProvince(province);
companyShop.setShopCity(city);
UserLoginDTO loginDTO = (UserLoginDTO) request.getSession()
.getAttribute("userLoginDTO");
if (loginDTO == null) {
logger.info("WebShopController addCompanyShop 用户未登录");
out.write("创建失败,用户未登录!");
return;
}
if (companyShop != null) {
companyShop.setCreateUser(loginDTO.getUsername());
}
if(!StringUtils.isEmpty(companyShop.getShopCard())){
CompanyShop shop = new CompanyShop();
shop.setShopCard(companyShop.getShopCard());
@SuppressWarnings("unchecked")
List<CompanyShop> shopList = (List<CompanyShop>) shopManager.queryShop(
shop, null, null).getResultData();
if (shopList.size() > 0) {
logger.info("WebShopController addCompanyShop 内卡已存在");
out.write("创建失败,内卡已存在!");
out.flush();
out.close();
return;
}
}
//上传店铺头像
if(!StringUtils.isEmpty(filePath)){
try {
filePath = request.getSession().getServletContext().getRealPath(filePath.substring(7));
logger.info("裁前图片路径:"+filePath+"裁剪尺寸,x={},y={},width={},height={}",imageX,imageY,imageWidth,imageHeight);
byte [] imgByte = ImgUtil.cut(Integer.parseInt(imageX),Integer.parseInt(imageY),
(int)Float.parseFloat(imageWidth), (int)Float.parseFloat(imageHeight), filePath,desWidth,desHeight);
if(imgByte != null&&imgByte.length>0){
companyShop.setShopPhoto(uploadService.imageUpload(imgByte, ImageType.jpg));
}
logger.info("裁前后图片路径:"+companyShop.getShopPhoto());
} catch (IOException e1) {
e1.printStackTrace();
out.write("创建店铺失败,头像图片处理异常!");
logger.error("创建店铺失败,头像图片处理异常!"+e1.getStackTrace());
if(out != null)
out.close();
return;
}
}
try {
Result rs = shopManager.insertShop(companyShop,
parentOrganizationId);
if (StringConstant.RESULT_FAIL.equals(rs.getSuccess())) {
out.write(rs.getData().toString());
out.flush();
out.close();
}
loginManager.setStoreNosToCache(MemberConstant.QUEUE_OF_ALL
+ loginDTO.getLoginName(), loginDTO.getOrganizNo());
logger.info("WebShopController addCompanyShop 添加成功");
out.write("success");
} catch (Exception e) {
logger.error("WebShopController addCompanyShop 出现异常:"
+ e.getMessage());
logger.error(e.getMessage(), e);
e.printStackTrace();
out.write("创建失败,出现异常!");
out.flush();
out.close();
return;
}
logUtil.saveLog(request, "新增【门店信息】"+companyShop.getShopName());
}
4.裁剪图片工具类
package cn.wonhigh.o2o.portal.common.util;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
/**
* 图片工具类
* @author xiangxg
*
*/
public class ImgUtil {
/** 对图片裁剪,并把裁剪完的新图片保存 */
/**
*
* @param x
* @param y
* @param width
* @param height
* @param srcPath
* @param desWidth缩放目标宽
* @param desHeight缩放目标高
* @return
* @throws IOException
*/
public static byte[] cut(int x, int y, int width, int height,
String srcPath, String desWidth, String desHeight)
throws IOException {
ByteArrayOutputStream srcImgStream = new ByteArrayOutputStream();
ByteArrayOutputStream destImgStream = new ByteArrayOutputStream();
// 对原图进行缩放
createThumb(srcPath, srcImgStream, Integer.parseInt(desWidth),
Integer.parseInt(desHeight));
ImageInputStream iis = null;
try {
/*
* 返回包含所有当前已注册 ImageReader 的 Iterator,这些 ImageReader 声称能够解码指定格式。
* 参数:formatName - 包含非正式格式名称 . (例如 "jpeg" 或 "tiff")等 。
*/
Iterator<ImageReader> it = ImageIO
.getImageReadersByFormatName("jpg");
ImageReader reader = it.next();
// 获取图片流
iis = ImageIO.createImageInputStream(new ByteArrayInputStream(
srcImgStream.toByteArray()));
/*
* < 此设置意味着包含在输入源中的图像将只按顺序读取,可能允许 reader
* 避免缓存包含与以前已经读取的图像关联的数据的那些输入部分。
*/
reader.setInput(iis, true);
/*
* 描述如何对流进行解码的类用于指定如何在输入时从 Java Image I/O
* 框架的上下文中的流转换一幅图像或一组图像。用于特定图像格式的插件 将从其 ImageReader 实现的
* getDefaultReadParam 方法中返回 ImageReadParam 的实例。
*/
ImageReadParam param = reader.getDefaultReadParam();
/*
* 图片裁剪区域。Rectangle 指定了坐标空间中的一个区域,通过 Rectangle 对象
* 的左上顶点的坐标(x,y)、宽度和高度可以定义这个区域。
*/
Rectangle rect = new Rectangle(x, y, width, height);
// 提供一个 BufferedImage,将其用作解码像素数据的目标。
param.setSourceRegion(rect);
/*
* 使用所提供的 ImageReadParam 读取通过索引 imageIndex 指定的对象,并将 它作为一个完整的
* BufferedImage 返回。
*/
BufferedImage bi = reader.read(0, param);
ImageIO.write(bi, "jpg", destImgStream);
destImgStream.flush();
return destImgStream.toByteArray();
} finally {
if (destImgStream != null)
destImgStream.close();
if (srcImgStream != null)
srcImgStream.close();
if (iis != null)
iis.close();
}
}
/**
*
* @param srcImgPath
* 待切割图片路径
* @param destImgPath
* 切割后图片路径
* @param destImgW
* 所需宽度
* @param destImgH
* 所需高度
* @throws IOException
*/
public static void createThumb(String srcImgPath,
ByteArrayOutputStream out, int destImgW, int destImgH)
throws IOException {
BufferedImage bi = ImageIO.read(new File(srcImgPath));
BufferedImage cutRightNarrowImg = adjustImage(bi, destImgW, destImgH);
ImageIO.write(cutRightNarrowImg, "JPEG", out);
}
public static void createThumb(byte[] srcImg, String destFile,
int destImgW, int destImgH) throws IOException {
BufferedImage bi = ImageIO.read(new ByteArrayInputStream(srcImg));
BufferedImage cutRightNarrowImg = adjustImage(bi, destImgW, destImgH);
File file = new File(destFile);
if(!file.exists()){
file.mkdirs();
}
ImageIO.write(cutRightNarrowImg, "JPEG", file);
}
private static BufferedImage adjustImage(BufferedImage bi, int destImgW,
int destImgH) throws IOException {
// 原图片等比例缩小或放大之后的图片
int narrowImgW;
int narrowImgH;
BufferedImage cutRightNarrowImg = null;
// 原图片大小
int srcImgW;
int srcImgH;
srcImgW = bi.getWidth();
srcImgH = bi.getHeight();
// 转换图片尺寸与目标尺寸比较 , 如果转换图片较小,说明转换图片相对于目标图片来说高较小,需要以高为基准进行缩放。
if ((float) srcImgW / srcImgH > (float) destImgW / destImgH) {
narrowImgW = (int) (((float) destImgH / (float) srcImgH) * srcImgW);
narrowImgH = destImgH;
// 按照原图以高为基准等比例缩放、或放大。这一步高为所需图片的高度,宽度肯定会比目标宽度宽。
int cutNarrowImgSize = (narrowImgW - destImgW) / 2;
BufferedImage narrowImg = new BufferedImage(narrowImgW, narrowImgH,
BufferedImage.TYPE_INT_RGB);
narrowImg.getGraphics().drawImage(
bi.getScaledInstance(narrowImgW, narrowImgH,
Image.SCALE_SMOOTH), 0, 0, null);
// 等比例缩放完成后宽度与目标尺寸宽度相比较 , 将多余宽的部分分为两份 ,左边删除一部分
Image image = narrowImg.getScaledInstance(narrowImgW, narrowImgH,
Image.SCALE_DEFAULT);
CropImageFilter cropFilter = new CropImageFilter(cutNarrowImgSize,
0, narrowImgW - cutNarrowImgSize, narrowImgH);
Image img = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(image.getSource(), cropFilter));
BufferedImage cutLiftNarrowImg = new BufferedImage(narrowImgW
- cutNarrowImgSize, narrowImgH, BufferedImage.TYPE_INT_RGB);
cutLiftNarrowImg.getGraphics().drawImage(img, 0, 0, null);
// 右边删除一部分
image = cutLiftNarrowImg.getScaledInstance(narrowImgW
- cutNarrowImgSize, narrowImgH, Image.SCALE_DEFAULT);
cropFilter = new CropImageFilter(0, 0, narrowImgW
- cutNarrowImgSize * 2, narrowImgH);
img = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(image.getSource(), cropFilter));
cutRightNarrowImg = new BufferedImage(narrowImgW - cutNarrowImgSize
* 2, narrowImgH, BufferedImage.TYPE_INT_RGB);
Graphics g = cutRightNarrowImg.getGraphics();
g.drawImage(img, 0, 0, null); // 绘制截取后的图
g.dispose();
// 输出为文件 最终为所需要的格式
} else { // 以宽度为基准
narrowImgW = destImgW;
narrowImgH = (int) (((float) destImgW / (float) srcImgW) * srcImgH);
int cutNarrowImgSize = (narrowImgH - destImgH) / 2;
BufferedImage narrowImg = new BufferedImage(narrowImgW, narrowImgH,
BufferedImage.TYPE_INT_RGB);
narrowImg.getGraphics().drawImage(
bi.getScaledInstance(narrowImgW, narrowImgH,
Image.SCALE_SMOOTH), 0, 0, null);
Image image = narrowImg.getScaledInstance(narrowImgW, narrowImgH,
Image.SCALE_DEFAULT);
CropImageFilter cropFilter = new CropImageFilter(0,
cutNarrowImgSize, narrowImgW, narrowImgH - cutNarrowImgSize);
Image img = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(image.getSource(), cropFilter));
BufferedImage cutTopNarrowImg = new BufferedImage(narrowImgW,
narrowImgH - cutNarrowImgSize, BufferedImage.TYPE_INT_RGB);
cutTopNarrowImg.getGraphics().drawImage(img, 0, 0, null);
image = cutTopNarrowImg.getScaledInstance(narrowImgW, narrowImgH
- cutNarrowImgSize, Image.SCALE_DEFAULT);
cropFilter = new CropImageFilter(0, 0, narrowImgW, narrowImgH
- cutNarrowImgSize * 2);
img = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(image.getSource(), cropFilter));
cutRightNarrowImg = new BufferedImage(narrowImgW, narrowImgH
- cutNarrowImgSize * 2, BufferedImage.TYPE_INT_RGB);
Graphics g = cutRightNarrowImg.getGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
}
return cutRightNarrowImg;
}
}