Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading Images from Mobile #22

Closed
madhall opened this issue Apr 30, 2021 · 2 comments
Closed

Loading Images from Mobile #22

madhall opened this issue Apr 30, 2021 · 2 comments

Comments

@madhall
Copy link

madhall commented Apr 30, 2021

Hi Tej,

The user is able to upload a default image using picasso, and the uri is stored. I tried the following approach to be able to display the image from the uri for the image stored in the phone gallery but it does not work... any suggestions please?

    val imageView = PDFImageView(applicationContext)
    val imageLayoutParam = LinearLayout.LayoutParams(
        60,
        60, 0F
    )
    if(user.logoUrl != null){
        val url = URL(user.logoUrl)
        val imageBmp = BitmapFactory.decodeStream(url.openConnection().getInputStream())
        imageView.setImageScale(ImageView.ScaleType.CENTER_INSIDE)
        imageView.setImageBitmap(imageBmp)
        // imageView.setImageResource(user!!.logoUrl)
        imageLayoutParam.setMargins(0, 0, 10, 10)
        imageView.setLayout(imageLayoutParam)
        horizontalView.addView(imageView)
    }

thanks

@madhall
Copy link
Author

madhall commented Apr 30, 2021

this is the error i get:

Caused by: java.net.MalformedURLException: unknown protocol: content

@tejpratap46
Copy link
Owner

This issue is not related to this library, please read how to get bitmap from local file.

try this

InputStream is = getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();

or this:

Uri mImageCaptureUri = data.getData();
Bitmap photoBmp = null;
if (mImageCaptureUri != null) {
    photoBmp = MediaStore.Images.Media.getBitmap(ac.getContentResolver(), mImageCaptureUri);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants