我正在尝试为我的相对布局动态添加缩略图。这是代码在这里在Android中动态添加缩略图
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) {
}
}
它从来没有显示任何
问候
你最好看看有没有在您的代码中抛出异常。它会告诉你更多关于创建'Bitmap'或'FileInputStream'等错误信息。 – 2012-02-15 05:32:30
写入EMPTY Catch块是不好的做法,总是把至少一个日志放在那里。 – MKJParekh 2012-02-15 05:36:51
你可以把整个代码放在这里吗? – Deva 2012-02-15 06:22:12