EditText的富媒体开发(Edittext显示网络图片) 一

来源:互联网 发布:windows 网络发现 编辑:程序博客网 时间:2024/06/10 21:26

                                         edittext里面需要插入图片或者文字

 第一步  首先,选择图片

         

/** * 从相册选择图片 */public void choseImgsFromAlbum() {    Intent intent = new Intent(            Intent.ACTION_PICK,            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);    startActivityForResult(intent, REQUEST_CODE_CHOSE_PIC_FROMALBUM);}


  

/** * 拍照 */public void choseImgFromCam() {    Intent takeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    // 下面这句指定调用相机拍照后的照片存储的路径    tempfileName = DateUtil.getSimpleDateYYYYMMDDHHMMM(System.currentTimeMillis()) + ".jpg";    takeIntent.putExtra(MediaStore.EXTRA_OUTPUT,            Uri.fromFile(new File(FileUtils.getTeaFilePath(), tempfileName)));    startActivityForResult(takeIntent, REQUEST_CODE_CHOSE_PIC_FROMCAM);}
然后在 OnactivityForResult里面

  

LogUtils.debug("ActivityResult" + requestCode);if (GeneralUtils.isEmpty(data))    return;switch (requestCode) {    case REQUEST_CODE_CHOSE_PIC_FROMALBUM:        //从相册选择        LogUtils.debug("从相册选择");        Bundle extras = data.getExtras();        File file = null;        if (GeneralUtils.isEmpty(extras)) {            LogUtils.debug("extras为空" + data);            Uri uri = data.getData();            if (uri != null) {                Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath());                //把bitmap转为file                file = saveBitmapFile(bitmap);                uploadPic(file);// 保存在SD卡中            }        } else {            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);            LogUtils.debug("从相册选择图片的Uri=" + imagePath);            Bitmap bi = BitmapFactory.decodeFile(imagePath);            saveBitmap(bi);            file = new File(FileUtils.getTeaFilePath(), "pic.jpg");            LogUtils.debug("保存图片" + file.exists());            uploadPic(file);        }        LogUtils.debug("从相册选择图片" + file.exists());        break;
public void saveBitmap(Bitmap mbitmap) {    FileOutputStream b = null;    String imageName = FileUtils.getTeaFilePath() + "pic.jpg";    try {        b = new FileOutputStream(imageName);        mbitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件    } catch (Exception e) {    }}

最后就是处理 图片显示了。


0 0