Guest User

Downloadable png to int[]

a guest
Jan 7th, 2015
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. private void downloadSkin()
  2.     {
  3.         HttpURLConnection httpurlconnection = null;
  4.         String username=mc.getSession().getUsername();
  5.         ModDNAT.logger.debug("Downloading "+username+"'s skin");
  6.         try
  7.         {
  8.             httpurlconnection = (HttpURLConnection)(new URL("http://skins.minecraft.net/MinecraftSkins/"+username+".png")).openConnection(Minecraft.getMinecraft().getProxy());
  9.             httpurlconnection.setDoInput(true);
  10.             httpurlconnection.setDoOutput(false);
  11.             httpurlconnection.connect();
  12.  
  13.             if (httpurlconnection.getResponseCode() / 100 != 2)
  14.             {
  15.                 ModDNAT.logger.error("Server response code did not return 200, skin servers might be down.");
  16.                 //At this point I'll change the GUI to a backup one in case of servers being down
  17.             }
  18.  
  19.             BufferedImage bufferedimage;
  20.             bufferedimage = ImageIO.read(httpurlconnection.getInputStream());
  21.             int i = bufferedimage.getWidth();
  22.             int j = bufferedimage.getHeight();
  23.             int[] aint = new int[i * j];
  24.             bufferedimage.getRGB(0, 0, i, j, aint, 0, i);
  25.             imagePixelData=aint;
  26.         }
  27.         catch (Exception exception)
  28.         {
  29.             ModDNAT.logger.error("Error occurred when downloading skin, however, skin servers seem to be up.", exception);
  30.             //Once again, backup code will initiate once the finally ends
  31.         }
  32.         finally
  33.         {
  34.             if (httpurlconnection != null)
  35.             {
  36.                 httpurlconnection.disconnect();
  37.             }
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment