Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1.  
  2. //Mia methodos en touti
  3. public static Bitmap getBitmapFromURL(String src) {
  4. try {
  5. URL url = new URL(src);
  6. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  7. connection.setDoInput(true);
  8. connection.connect();
  9. InputStream input = connection.getInputStream();
  10. Bitmap myBitmap = BitmapFactory.decodeStream(input);
  11. return myBitmap;
  12. } catch (IOException e) {
  13. e.printStackTrace();
  14. return null;
  15. }
  16. }
  17.  
  18. //I alli en touti
  19. private byte[] Blogthemage(String url){
  20. try {
  21. URL imageUrl = new URL(url);
  22. URLConnection urlConnection = imageUrl.openConnection();
  23. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  24. InputStream is = urlConnection.getInputStream();
  25.  
  26. BufferedInputStream bis = new BufferedInputStream(is);
  27. byte[] data = new byte[500];
  28. int current = 0;
  29. while ((current = bis.read(data,0,data.length)) != -1) {
  30. buffer.write(data,0,current);
  31. }
  32.  
  33. return data;
  34.  
  35. } catch (Exception e) {
  36. Log.d("ImageManager", "Error: " + e.toString());
  37. }
  38. return null;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement