0
現在我開發了一個需要將圖像上傳到我的服務器的android應用程序。但是當我嘗試加載圖像到ImageView它只是顯示空白。當我將分辨率從1300像素更改爲300像素時,圖像可顯示在ImageView
。我的代碼我喜歡下面。請幫忙如何調整從相機捕獲的圖像並在imageview上顯示
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
viewImage = (ImageView)findViewById(R.id.imgInv);
int width = viewImage.getWidth();
int height = viewImage.getHeight();
Bitmap bitmap;
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inJustDecodeBounds = true;
bitmapOptions.inJustDecodeBounds = false;
bitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
bitmapOptions.inDither = true;
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(),bitmapOptions);
viewImage.setImageBitmap(bitmap);
OutputStream outFile = null;
File file = new File(path,String.valueOf(System.currentTimeMillis()) + ".jpg");
imgName = mName + "_" + String.valueOf(System.currentTimeMillis());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, baos);
byte[] b = baos.toByteArray();
imgData = Base64.encodeToString(b,Base64.DEFAULT);
}
}
你得到一個有效的「位圖」嗎?你可以只添加日誌並查看'bitmap.getHeight()'和'bitmap.getWidth()'嗎? – Henry
爲什麼你這樣做:bitmapOptions.inJustDecodeBounds = true; bitmapOptions.inJustDecodeBounds = false; –
我遵循我在網上找到的代碼。 – vic3ai