繁体   English   中英

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

[英]How to resize image that captured from camera and display on imageview

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

}

我不是在谈论您的代码,但是有一个您想要的库。
您可以使用Picasso库,该库具有用于处理图像的完整功能,例如下载,缓存等。您可以从此处获取示例。
也有一个关于它的教程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM