Retrieve bitmap from uri

前端 未结 7 1717
终归单人心
终归单人心 2021-01-01 17:06

I have included \'share via myApp\' option. I inserted following code in the receiving activity class.

    // Get the intent that started this activity
    I         


        
7条回答
  •  自闭症患者
    2021-01-01 17:51

    Please prefer this link.

    This is what you are looking for How to get Bitmap from an Uri?

    Try this it works for me:

    public static Bitmap getBitmapFromURL(String src) {
            try {
                System.out.printf("src", src);
                URL url = new URL(src);
                HttpURLConnection connection = (HttpURLConnection) url
                        .openConnection();
                connection.setDoInput(true);
                connection.connect();
                InputStream input = connection.getInputStream();
                Bitmap myBitmap = BitmapFactory.decodeStream(input);
                System.out.printf("Bitmap", "returned");
                myBitmap = Bitmap.createScaledBitmap(myBitmap, 100, 100, false);//This is only if u want to set the image size.
                return myBitmap;
            } catch (IOException e) {
                e.printStackTrace();
                System.out.printf("Exception", e.getMessage());
                return null;
            }
    

提交回复
热议问题