我正在嘗試爲我的相對佈局動態添加縮略圖。這是代碼在這裏在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