现在我开发了一个需要将图像上传到我的服务器的Android应用程序。但是当我尝试将图像加载到imageview时,它只显示空白。当我将分辨率从1300像素更改为300像素时,图像可以显示在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);
}
}