的Andr​​oid如何创建运行时缩略图缩略图、Andr、oid

2023-09-11 20:26:25 作者:黒色ン誘惑灬

我有一个大尺寸图像。在运行时,我想从存储器读取图像并进行缩放,使得其重量和体积会减少,我可以把它作为一个缩略图。当用户点击缩略图,我想要显示的全幅图像。

I have a large sized image. At runtime, I want to read the image from storage and scale it so that its weight and size gets reduced and I can use it as a thumbnail. When a user clicks on the thumbnail, I want to display the full-sized image.

推荐答案

我的解决方案

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) {

        }