In this code, variable “byteImageValue” is the actual image byte code.
       
byte[] byteResizedImageValue;
       
try {
              ByteArrayInputStream inputStream =
new ByteArrayInputStream(byteImageValue);
                     ByteArrayOutputStream baos =
new ByteArrayOutputStream();
                    
byte[] imageInByte =
null; 
                     BufferedImage bufferedImage = ImageIO.read(inputStream);
                    
int intResizeWidth = bufferedImage.getWidth()+25;
                    
int intResizedHeight = bufferedImage.getHeight()+10;
                     BufferedImage resizedImage =
new BufferedImage(intResizeWidth, intResizedHeight, BufferedImage.TYPE_INT_ARGB);
                     Graphics g = resizedImage.getGraphics();
                     g.drawImage(bufferedImage, 0, 0, intResizeWidth, intResizedHeight,
null);
               g.dispose();
                     ImageIO.write(resizedImage,
"PNG", baos );
               baos.flush();
               imageInByte = baos.toByteArray();
               baos.close();
               byteResizedImageValue = imageInByte; 
              }
catch (IOException objImageIOException) {
                    
// 
TODO Auto-generated catch block
                    
throw
new ScriptException(generalErrorCode,
                   
"Invalid image." + objImageIOException.getMessage());
              }
 
 
No comments:
Post a Comment