将Url转成File文件

来源:互联网 发布:最近网络上很火的舞蹈 编辑:程序博客网 时间:2024/06/06 13:05
if (requestCode == 200 && resultCode == Activity.RESULT_OK && data != null) {        Uri selectedImage = data.getData();    String[] filePathColumns = {MediaStore.Images.Media.DATA};    Cursor c = getContentResolver().query(selectedImage, filePathColumns, null, null, null);    c.moveToFirst();    int columnIndex = c.getColumnIndex(filePathColumns[0]);    String imagePath = c.getString(columnIndex);    showImage(imagePath);    c.close();    }

private void showImage(String imaePath){    try {        Bitmap bm = BitmapFactory.decodeFile(imaePath);        File file = new File(imaePath);        imageView.setImageBitmap(bm);        imageView.setScaleType(ImageView.ScaleType.FIT_XY);        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));        bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);        uploadPic(file);        bos.flush();        bos.close();    } catch (IOException e) {        e.printStackTrace();    }}
原创粉丝点击