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
最新推荐文章于 2022-10-26 20:35:24 发布