public void setParameters(SAPObject obj)
throws Exception{
/* Other required code*/
String imageString = "";
String fileresize = this._user.getString("transaction.ZResizeValue"); //achieving the file resize parameter from client (L= Large, M= Medium, S= Small)ResizeValue
if (this._documentLink.isPicture()) {
imageString = this._documentLink.getPicture();
}
/* Other required code*/
byte[] bytes = ConversionUtility.hexStringToByteArray(imageString);
//byte array created from the file data
if(!(fileresize.equalsIgnoreCase(""))&& this._documentLink.isPicture() ){
bytes = getResizedImage(bytes, this._documentLink.getFileType(), fileresize);
}
//getResizedImage() method is called only if the file is image and the resizing factor is present.
/* Other required code*/
setValue(this._imports, log, "IS_FILE_CONTENT_BIN", bytes);
//the resized byte array is passed to the BAPI Wrapper.
}
public byte[] getResizedImage(byte [] bytes, String filetype, String filesize) throws FileNotFoundException, IOException{
//the method to resize the image and provide a byte array out of it.
InputStream inputStream = new ByteArrayInputStream(bytes);
float imageQuality = 0.0f;
if(filesize.equalsIgnoreCase("L")){
imageQuality = 1.0f;
}
if (filesize.equalsIgnoreCase("M")){
imageQuality = 0.7f;
}
if (filesize.equalsIgnoreCase("S")){
imageQuality = 0.5f;
}
//the image quality is defined by the resizing factor. L=100%, M=70%, S=50%
BufferedImage bufferedImage = ImageIO.read(inputStream);
int scaledwidth = bufferedImage.getWidth();
int scaledheight = bufferedImage.getHeight();
// a buffered image for actual image is created to get the actual height and width
byte [] imageInByte;
BufferedImage resizedImage = new BufferedImage((int) ((int)scaledwidth*imageQuality),(int) ((int)scaledheight*imageQuality) , bufferedImage.getType());
//a resized buffer image is created
Graphics2D g2d = resizedImage.createGraphics();
g2d.drawImage(bufferedImage, 0, 0,(int) ((int)scaledwidth*imageQuality),(int) ((int)scaledheight*imageQuality), null);
g2d.dispose();
//the actual image is scaled to the resized image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(resizedImage, filetype, baos);
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
//the resized image is converted to Byte Array
return imageInByte;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |