android - 资源中图像的缩略图

标签 android image thumbnails

我想制作一张图片的缩略图。图片在资源可绘制文件中。谁能帮帮我。

最佳答案

试试这段代码

     im=(ImageView)findViewById(R.id.imageView1);

    byte[] imageData = null;

    try 
    {

    final int THUMBNAIL_SIZE = 64;
    //InputStream is=getAssets().open("apple-android-battle.jpg");
    FileInputStream fis = new FileInputStream("/sdcard/apple.jpg");
    Bitmap imageBitmap = BitmapFactory.decodeStream(fis);

    Float width = new Float(imageBitmap.getWidth());
    Float height = new Float(imageBitmap.getHeight());
    Float ratio = width/height;
    imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int)(THUMBNAIL_SIZE * ratio), THUMBNAIL_SIZE, false);

    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    imageData = baos.toByteArray();
    im.setImageBitmap(imageBitmap);
    }
    catch(Exception ex) {

    }

关于android - 资源中图像的缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9461283/

相关文章:

android - 如何使用 AsyncTask 和 Timer 获取 XML?

android - 使用camera2 API createCaptureSession后,Android无法仅播放视频音频

android - 单击 ListView 项时更改为特定 Activity

image - CSS 中的内容属性以显示图像图标

php - 从 dataURL 创建/显示图像

c# - Windows API 代码包 - ShellFile 不生成 PDF 位图

php - 使用PHP在CentOS上生成网站截图

Android Recycler View 滚动到底部

python - 如何以编程方式在 django oscar 中添加产品图片?

php - 来自视频 ID 的 Vimeo 缩略图