通过URl将服务器的图片下载到本地并压缩

private void downloadServerPic(final String url1) {

new Thread() {

@Override

public void run() {

// 定义一个URL对象

URL url;

try {

url = new URL(url1);

// 打开该URL的资源输入流

InputStream is = url.openStream();

is.close();

// 再次打开RL对应的资源输入流

is = url.openStream();

//创建输出流

    FileOutputStream outStream = null;

try {

        byte[] bary = readInputStream(is);

        File imageFile = new File( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");

        outStream = new FileOutputStream(imageFile);

              //写入数据

              outStream.write(bary);

        //getimage 方法见  http://www.cnblogs.com/wangzehuaw/p/4447120.html

              bitMap = getimage( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");

             //关闭输出流

        } catch (Exception e) {

        e.printStackTrace();

        } finally {

          if(outStream != null)

            outStream.close();

            is.close();

        }

  } catch (MalformedURLException e) {    

      e.printStackTrace();

   } catch (IOException e) {

    e.printStackTrace();

  }

  }

  }.start();

}

时间: 2024-08-28 21:02:44

通过URl将服务器的图片下载到本地并压缩的相关文章

将网页中的图片下载到本地的方法

/** * 传入要下载的图片的url列表,将url所对应的图片下载到本地 * @param urlList */ public static String downloadPicture(String urlString,String path) { URL url = null; String imgPath = null; try { url = new URL(path+urlString); // 打开URL连接 URLConnection con = url.openConnectio

怎样将svn服务器的内容下载到本地计算机

一.下载 根据自己电脑是32位还是64位的版本下载 TortoiseSVN. 二.安装 1.下载软件后,双击程序进行安装,点击“Next”: 2.在许可证协议页面,选择“I Accept the terms in the License Agreement”,点击“Next”: 3.在自定义选项页面,可以选择安装目录,也可以直接点击“Next”进行安装: 4.点击“Install”开始安装: 5.安装完成后,点击“Finsh”: 三.将svn服务器的内容下载到本地 1.新建文件夹,打开文件夹,在

scrapy框架来爬取壁纸网站并将图片下载到本地文件中

首先需要确定要爬取的内容,所以第一步就应该是要确定要爬的字段: 首先去items中确定要爬的内容 class MeizhuoItem(scrapy.Item): # define the fields for your item here like: # name = scrapy.Field() # 图集的标题 title = scrapy.Field() # 图片的url,需要来进行图片的抓取 url = scrapy.Field() pass 在确定完要爬的字段之后,就是分析网站页面的请求

用thinkphp将网络上的图片下载到本地服务器

我用的thinkphp版本是3.2.3,这个版本的跟更早些版本的调用方法不太一样,正确的调用方法是: Demo3Controller.class <?php namespace Home\Controller; use Think\Controller; class Demo3Controller extends Controller { public function download(){ $url = "http://n.sinaimg.cn/sports/20161023/MrD2

简单的从服务器获取图片保存到本地

1.先创建一个web工程,在webroot目录下放一张图片 2.将工程挂到服务器 3.创建一个java工程 源码:(myhhtp工程) package myhttp; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; imp

svg保存为图片下载到本地

今天给大家说一个将svg下载到本地图片的方法,这里我不得不吐槽一下,为啥博客园不可以直接上传本地文件给大家用来直接下载分享呢,好,吐槽到此为止! 这里需要用到一个js文件,名字自己起,内容如下: (function() { const out$ = typeof exports != 'undefined' && exports || typeof define != 'undefined' && {} || this || window; if (typeof defin

抓取服务器图片下载到本地

Sample code: import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods

【android】 如何把gif图片下载到本地

以上图片大家可以看到,虽然是个jpg格式的文件,但是本质上是个动图. 但是发现在咱的图片模块下,本地存储的图片只有一帧,问题出在哪里呢? http获取到的byte[]数据是没问题的 断点跟踪了下,发现问题出现在最后一句压缩图片尺寸的时候. public static Bitmap getScaledBitMap(byte[] data, int width, int height) { BitmapFactory.Options options = new BitmapFactory.Optio

Android图片下载到本地,系统图库不显示

可能大家都知道我们下载图片到Android手机的时候,然后调用系统图库打开图片,提示"找不到指定项". 那是因为我们插入的图片还没有更新的缘故,所以只要将图片插入系统图库,之后发条广播就ok了. /** * 图片插入到系统相册,解决系统图库不能打开图片的问题 */ public static void insertImageToSystemGallery(Context context, String filePath, Bitmap bitmap){ MediaStore.Image