Java 如何调整从相机捕获并显示在imageview上的图像的大小

Java 如何调整从相机捕获并显示在imageview上的图像的大小,java,android,Java,Android,现在我开发了一个android应用程序,需要将图像上传到我的服务器上。但当我尝试将图像加载到imageview时,它只显示为空白。当我将分辨率从1300像素更改为300像素时,图像可以显示在ImageView。下面是我喜欢的代码。请帮忙 protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, res

现在我开发了一个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);
         }

}

我不是在说你的代码,但是有一个你想要的库。
你可以使用
毕加索
库,它有完整的图像处理功能,如下载、缓存等。 你可以通过一个例子从中得到它。

还有一个关于它的问题

您是否得到了有效的
位图
?您是否可以添加日志并查看
bitmap.getHeight()
bitmap.getWidth()
?为什么这样做:bitmapOptions.inJustDecodeBounds=true;bitmapOptions.inJustDecodeBounds=false;我遵循我在网上找到的代码。