+ 1
How to render image in picasso from an url in low quality, (to make it load faster in slow net)
((Java))! Im using picasso to display images, in a recyclerview some images in url are big, how can I retrieve them as compressed
3 Réponses
+ 8
Use Java DIP Technique
The following example demonstrates the use of ImageWriteParam class to compress an image −
import java.io.*; import java.util.*; import java.awt.image.*; import javax.imageio.*; import javax.imageio.stream.ImageOutputStream; class Compression { public static void main(String[] args) throws IOException { File input = new File("digital_image_processing.jpg"); BufferedImage image = ImageIO.read(input); File compressedImageFile = new File("compress.jpg"); OutputStream os =new FileOutputStream(compressedImageFile); Iterator<ImageWriter>writers = ImageIO.getImageWritersByFormatName("jpg"); ImageWriter writer = (ImageWriter) writers.next(); ImageOutputStream ios = ImageIO.createImageOutputStream(os); writer.setOutput(ios); ImageWriteParam param = writer.getDefaultWriteParam(); param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); param.setCompressionQuality(0.05f); writer.write(null, new IIOImage(image, null, null), param); os.close(); ios.close(); writer.dispose(); } }
+ 8
Output
When you execute the given code, it compresses the image digital_image_processing.jpg to its equivalent compressed image and writes it on the hard disk with the name compress.jpg.
+ 2
Khalid Shaikh
Is there any other way without writing to hard disk