从网络获取图片直接存为bitmap

URL url= new URL(urlString);
  URLConnection connection=url.openConnection();
  HttpURLConnection httpConnection=(HttpURLConnection)connection;
  int responseCode=httpConnection.getResponseCode();
  if (responseCode==HttpURLConnection.HTTP_OK){
  InputStream stream=httpConnection.getInputStream();
  Bitmap bitmap=BitmapFactory.decodeStream(stream);
  int []buffer= new int [bitmap.getHeight()
  * bitmap.getWidth()];
  bitmap.getPixels(buffer, 0 , bitmap.getWidth(), 0 , 0 ,
  bitmap.getWidth(), bitmap.getHeight());
  graphics2D.drawImage(buffer,bitmap.getWidth(),
  bitmap.getHeight(),(x- 6 )* 256 ,(y- 3 )* 256 );


你可能感兴趣的:(从网络获取图片直接存为bitmap)