0

我正在尝试从 url 中获取和读取不同的图像...... 字符串名称数组完成 url。并将图像保存在内部存储中。我就是这样给它打虫的

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);
            }
        }

但是按照我存储的方式,它意味着有三张图像..如何像第二张或第三张一样查看,因为它们有文件名。

4

0 回答 0