gpt4 book ai didi

android - 资源中图像的缩略图

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:00:14 27 4
gpt4 key购买 nike

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

最佳答案

试试这段代码

     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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com