How to set a bitmap from resource

前端 未结 6 1253
温柔的废话
温柔的废话 2020-12-22 15:52

This seems simple, I am trying to set a bitmap image but from the resources, I have within the application in the drawable folder.

bm = BitmapFactory.decodeR         


        
6条回答
  •  悲&欢浪女
    2020-12-22 16:29

    Using this function you can get Image Bitmap. Just pass image url

     public Bitmap getBitmapFromURL(String strURL) {
          try {
            URL url = new URL(strURL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
          } catch (IOException e) {
            e.printStackTrace();
            return null;
          }
     }
    

提交回复
热议问题