簡體   English   中英

Android中如何壓縮下載的圖片並在需要時解壓?

[英]How to compress downloaded images and decompress when needed in Android?

如何壓縮可以存儲在內存中的 jpg/bmp 文件,然后在需要時解壓縮這些圖像並顯示給用戶而不會損失太多圖像質量? 如何進行壓縮和解壓縮,任何指導/鏈接都會有所幫助。 謝謝

創建圖像縮略圖

'byte[] imageData = null;

    try     
    {

        final int THUMBNAIL_SIZE = 64;

        FileInputStream fis = new FileInputStream(fileName);
        Bitmap imageBitmap = BitmapFactory.decodeStream(fis);

        imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        imageData = baos.toByteArray();

    }
    catch(Exception ex) {

    }`

如果你需要拇指指甲,那么使用 ThumbNailUtils.extractThumbnail(Bitmap source,int width,int height) 它從位圖顯示縮略圖,當你想顯示原始位圖時然后顯示位圖。 明智地使用位圖對象,因為它在運行時需要更多內存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM