当前位置: 代码迷 >> Android >> 请教从多个网络图片读取后,保存多个名字图片名字的有关问题
  详细解决方案

请教从多个网络图片读取后,保存多个名字图片名字的有关问题

热度:30   发布时间:2016-04-28 01:26:02.0
请问从多个网络图片读取后,保存多个名字图片名字的问题
请问以下这个效果怎么实现呢?
比如有50个网络图片,比如
http://d.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=ed20149d0b7b020818c437b303b099b6/91ef76c6a7efce1b1e30f4f2ae51f3deb48f65ea.jpg?qq-pf-to=pcqq.c2c

http://abc.com/a
http://abc.com/b
.....
......
http://abc.com/z
假如以上是100个网络图片的链接

请问  怎么把以上一百个网络图片的链接,经过处理后, 保存在sd卡内的有规律的图片名呢?

比如 保存在"/storage/sdcard0/"里边
"/storage/sdcard0/photoA .jpg"
"/storage/sdcard0/photoB.jpg"
"/storage/sdcard0/photoC.jpg"
....
......
"/storage/sdcard0/photoZ .jpg"

也就是图片名字是有规律的,关键是为方便以后把这些图片在界面上显示出来。  麻烦会的朋友帮忙回复下,谢啦


public static Bitmap getHttpBitmap(String path) {  // 将网络图片链接转化为 bitmap
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
.penaltyLog().penaltyDeath().build()); 

Bitmap bitmap = null;
try {

URL url = new URL(path);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setDoInput(true);
conn.connect();

InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is); 
Log.d(TAG, "bitmap= "+bitmap);
savePicToSdcard(bitmap,Test_Source,imageName);

is.close(); // 
conn.disconnect(); 

} catch (Exception e) {
Log.e(TAG, "鑾峰彇鍥剧墖澶辫触锛侊紒锛 ");
e.printStackTrace();
}

return bitmap;
}


public static String savePicToSdcard(Bitmap bitmap, String path, String fileName) {    // 保存到sdcard内
     String filePath = "";   
     if (bitmap == null) {   
        return filePath;   
     } else {   
     filePath=path + fileName;   
     File destFile = new File(filePath);   
     FileOutputStream os = null;
     try {   
     os = new FileOutputStream(destFile);   
     bitmap.compress(CompressFormat.JPEG, 100, os);
     os.flush();   
         os.close();   
     } catch (IOException e) {   
     filePath = ""; 
     e.printStackTrace();
     }   
     }   
     return filePath;   
    }
------解决思路----------------------
当你下载了一个图片的时候 你在图片的名字后面加上索引 比如:
image001.jpg
image002.jpg 
你需要记住你当前的索引是多少,因此你要把索引记录在SharedPreference 这样下载好的图片 都是按照索引,以后每次叠加索引即可。
你取图片出来的时候通过列表排序即可。
------解决思路----------------------
你图片都存在sdcard里面了,你扫描一下SDCARD 把都取出来。然后根据你逻辑进行排序。
------解决思路----------------------
“image"+数字,每保存一张,数字+1,如果要用00或010这种格式的,做个数字判断,再拼接就行了。
  相关解决方案