|  |  |  | 
|---|
|  |  |  | int compressedWidth = (int) (originalImage.getWidth() / compressionRatio); | 
|---|
|  |  |  | int compressedHeight = (int) (originalImage.getHeight() / compressionRatio); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BufferedImage compressedImage = new BufferedImage(compressedWidth, compressedHeight, originalImage.getType()); | 
|---|
|  |  |  | BufferedImage compressedImage = new BufferedImage(compressedWidth, compressedHeight, BufferedImage.TYPE_INT_RGB); | 
|---|
|  |  |  | Graphics2D graphics = compressedImage.createGraphics(); | 
|---|
|  |  |  | graphics.drawImage(originalImage, 0, 0, compressedWidth, compressedHeight, null); | 
|---|
|  |  |  | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | 
|---|
|  |  |  | ImageOutputStream imOut = ImageIO.createImageOutputStream(byteArrayOutputStream); | 
|---|
|  |  |  | ImageIO.write(compressedImage, "JPEG", imOut); | 
|---|
|  |  |  | ImageIO.write(compressedImage, "jpg", imOut); | 
|---|
|  |  |  | InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); | 
|---|
|  |  |  | graphics.dispose(); | 
|---|
|  |  |  | return inputStream; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | 
|---|
|  |  |  | ImageOutputStream imOut = ImageIO.createImageOutputStream(byteArrayOutputStream); | 
|---|
|  |  |  | ImageIO.write(originalImage, "JPEG", imOut); | 
|---|
|  |  |  | ImageIO.write(originalImage, "jpg", imOut); | 
|---|
|  |  |  | InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); | 
|---|
|  |  |  | return inputStream; | 
|---|
|  |  |  | } | 
|---|