我正在尝试昆虫并从网址中读取不同的图像.. 。字符串名称数组完成网址。并将图像保存在内部存储中。 这就是我如何取消它
String[] name={"dove.jpg","man.jpg","rat.jpg"};
String fileName="code";
try {
URL url = new URL("http://10.0.2.2/picure/"+name");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
Bitmap bm = BitmapFactory.decodeStream(is);
FileOutputStream fos = getActivity().openFileOutput(fileName, Context.MODE_PRIVATE);
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
byte[] byteArray = outstream.toByteArray();
fos.write(byteArray);
fos.close();
Toast.makeText(getActivity()," connected", Toast.LENGTH_LONG).show();
} catch(Exception e) {
}
这就是我想读它的方式
category_logo = (ImageView) view.findViewById(R.id.img_category_logo);
String path = mContext.getFilesDir().toString();
String fileName = "code";
if (fileName != null && !fileName.equals("")) {
Bitmap bMap = BitmapFactory.decodeFile(path + "/" + fileName);
if (bMap != null) {
category_logo.setImageBitmap(bMap);
}
}
但是按照我存储它的方式,它意味着有三个图像..如何查看第二个或第三个图像,因为它们有文件名。