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

Android 码拜 9年前 (2015-04-26) 876次浏览 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;   
    }

请问从多个网络图片读取后,保存多个名字图片名字的问题
20分
当你下载了一个图片的时候 你在图片的名字后面加上索引 比如:
image001.jpg
image002.jpg 
你需要记住你当前的索引是多少,因此你要把索引记录在SharedPreference 这样下载好的图片 都是按照索引,以后每次叠加索引即可。
你取图片出来的时候通过列表排序即可。
请问从多个网络图片读取后,保存多个名字图片名字的问题
引用 1 楼 birdsaction 的回复:

当你下载了一个图片的时候 你在图片的名字后面加上索引 比如:
image001.jpg
image002.jpg 
你需要记住你当前的索引是多少,因此你要把索引记录在SharedPreference 这样下载好的图片 都是按照索引,以后每次叠加索引即可。
你取图片出来的时候通过列表排序即可。

@birdsaction   谢谢回复

请问 当可以拿到 比如 http://d.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=ed20149d0b7b020818c437b303b099b6/91ef76c6a7efce1b1e30f4f2ae51f3deb48f65ea.jpg?qq-pf-to=pcqq.c2c   这个 网络图片的时候,

在代码中 如何 通过我上面写的那两个函数处理后, 接着 把它保存为图片名为 image001.jpg呢?  也就是把处理后保存图片名的代码怎么写呢。

然后 我有个大疑问是   对应用sharepreference保存的问题, 您的意思是 比如 
key   value
001     image001.jpg的路径地址    还是什么呢?  

取图片出来的时候通过列表排序即可”  这个什么意思呢? 取图片如果不知道图片的地址的话,怎么取图片?
麻烦再帮忙回复  谢谢啦

请问从多个网络图片读取后,保存多个名字图片名字的问题
20分
你图片都存在sdcard里面了,你扫描一下SDCARD 把都取出来。然后根据你逻辑进行排序。
请问从多个网络图片读取后,保存多个名字图片名字的问题
引用 3 楼 birdsaction 的回复:

你图片都存在sdcard里面了,你扫描一下SDCARD 把都取出来。然后根据你逻辑进行排序。

@ birdsaction   谢谢您的回复

请问 代码里边怎么写保存的图片名字为 image001.jpg  ,image002.jpg ,image003.jpg等等
麻烦帮忙回复下  谢谢啦

请问从多个网络图片读取后,保存多个名字图片名字的问题
引用 3 楼 birdsaction 的回复:

你图片都存在sdcard里面了,你扫描一下SDCARD 把都取出来。然后根据你逻辑进行排序。

@ birdsaction   谢谢您的回复

请问 如果 把网络图片经过函数处理后,得到了 bitmap.
那么怎么把这个 bitmap的数据 保存为   图片名为image001.jpg的图片呢?  麻烦帮忙说下这个保存的代码怎么写吧,谢谢啦

请问从多个网络图片读取后,保存多个名字图片名字的问题
50分
“image”+数字,每保存一张,数字+1,如果要用00或010这种格式的,做个数字判断,再拼接就行了。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明请问从多个网络图片读取后,保存多个名字图片名字的问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!