//This is logic to crop image in java , here the code for how to crop image in java only. not this code runs completely
public void cropImage() {
byte[] bytesOut = null;
try {
int x1 = 0, y1 = 0, cw = 0, ch = 0;
HttpServletRequest request = getRequest();
String params = request.getParameter("dimensions");
String str[] = params.split(",");
HttpSession session = request.getSession();
String fname = (String) session.getAttribute("fileupload_name");
if (StringUtils.isNotBlank(str[0])) {
x1 = str[0].equals("") ? 50 : Integer.parseInt(str[0]);
y1 = str[1].equals("") ? 50 : Integer.parseInt(str[1]);
cw = str[2].equals("") ? 50 : Integer.parseInt(str[2]);
ch = str[3].equals("") ? 50 : Integer.parseInt(str[3]);
}
byte[] bytes = (byte[]) session .getAttribute("fileupload_bytes");
File tfile = new File(fname);
FileOutputStream fout = new FileOutputStream(tfile);
fout.write(bytes);
fout.close();
try{
BufferedImage bimage = ImageIO.read(tfile);
BufferedImage bi = null;
bi = bimage.getSubimage(x1, y1, cw, ch);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String format = fname.substring(fname.lastIndexOf(".") + 1);
if (bi != null) {
ImageIO.write(bi, format, baos);
}
bytesOut = baos.toByteArray();
}catch(Exception exp){
log.info("Invalid image Width or Height");
}
} catch (Throwable th) {
ExceptionTrapSender.sendException(th);
}
}
Let us share our views in java. Not only java, we can also share examples and configurations on Spring, Hibernate, javascript, CSS and Sqlserver queries. This blog will help you in giving the complete information and resolving your complete java related problems like the problems in core java, servlets, jsp spring, hibernate. And also the web technologies which includes all css related problems(Web 2.0).and java script and the latest smart jquery java script frame work
Showing posts with label Image Cropping in java; Image crop in java. Show all posts
Showing posts with label Image Cropping in java; Image crop in java. Show all posts
May 8, 2008
Subscribe to:
Posts (Atom)