如何从drawable文件夹复制图像并粘贴到android中的文件目录?

如何从drawable文件夹复制图像并粘贴到android中的文件目录?,android,Android,我想从drawable复制图像并粘贴到android的文件目录中? 注意:文件目录位于DDMS文件资源管理器中 我在drawalbe中有很多图像,它被设置在gridview中,当我点击特定的按钮时,我在每个图像上都设置了一个按钮,它是复制并粘贴到文件目录中的 可能吗 这是我的适配器类 public class ImageAdapter extends BaseAdapter { String[] name; Context context; int[] imageId;

我想从drawable复制图像并粘贴到android的文件目录中? 注意:文件目录位于DDMS文件资源管理器中

我在drawalbe中有很多图像,它被设置在gridview中,当我点击特定的按钮时,我在每个图像上都设置了一个按钮,它是复制并粘贴到文件目录中的

可能吗

这是我的适配器类

public class ImageAdapter extends BaseAdapter {

    String[] name;
    Context context;
    int[] imageId;

    private static LayoutInflater inflater = null;

    public ImageAdapter(Context context,String[] name, int[] imageId) {
        this.name=name;
        this.context = context;
        this.imageId = imageId;
        inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return this.name.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public class Holder {
        ImageButton btnDownload;
        ImageView img;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Holder holder = new Holder();
        final View rowView;

        rowView = inflater.inflate(R.layout.custome_image, null);
        holder.btnDownload = (ImageButton) rowView.findViewById(R.id.btndownload);
        holder.img = (ImageView) rowView.findViewById(R.id.imageView1);
        holder.img.setAdjustViewBounds(true);
        final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), imageId[position]);
        int height = (bitmap.getHeight() * 512 / bitmap.getWidth());
        Bitmap scale = Bitmap.createScaledBitmap(bitmap, 512, height, true);
        holder.img.setImageBitmap(scale);
        holder.btnDownload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    File root = new File(context.getFilesDir(), "IMAGES");

                    if (!root.exists()) {
                        root.mkdirs();
                    }

                    File file=new File(root+File.separator+position+".jpeg");
                    Log.e("Path", "" + file);
                    file.createNewFile();

                    FileOutputStream fos = new FileOutputStream(file);
                    fos.write(position);
                    fos.close();
                }
                catch (Exception e){
                    e.printStackTrace();
                }
            }
        });

        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(rowView.getContext(), FullImaeActivity.class);
                intent.putExtra("id", position);
                //Uri path = Uri.parse("android.resource://com.domore.Angelnx/" + position);

                String imgpath=path.toString();
                Log.e("ImagePath",imgpath);
                rowView.getContext().startActivity(intent);
            }
        });
        return rowView;
    }
    public void moveImage(){

    }
}
请帮助我解决此任务的任何人。

替换

fos.write(position)


另外,如果要保存图像文件,请将外部写入权限添加到manifest.xml

,这可能会对您有所帮助
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); 
fos.flush();