我正在尝试将缩略图动态添加到我的相关布局中。这是这里的代码
public void showViewOfReceipt(String fileName)
{
byte[] imageData = null;
try
{
final int THUMBNAIL_SIZE = 64;
FileInputStream fis = new FileInputStream(fileName);
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();
ImageView image = new ImageView(this);
image.setImageBitmap(imageBitmap);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.expLayout5);
layout.addView(image);
}
catch(Exception ex) {
}
}
它从不显示任何内容
问候
最佳答案
更改您的以下代码行,
catch(Exception ex)
{
}
到,
catch(Exception ex)
{
e.printStack();
}
所以,如果有的话,你会得到错误。
关于java - 在android中动态添加缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9288281/