从相机捕获图像并获得具有高质量图像的所有设备的路径

时间:2016-05-14 09:34:44

标签: android android-intent path camera

下面是我的代码。一切都很好,但我的图像非常模糊。 首先从数据中获取图像然后从位图Iam获取其路径。

  @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
           if (resultCode == Activity.RESULT_OK) {
            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            try {
                Uri fileUri = getImageUri(getApplicationContext(),bitmap);
                resultPath = getPath(getApplicationContext(), fileUri);
                mFileStatus.setText(resultPath);
            }catch (NullPointerException ne){
                saveBitmap(bitmap);
            }

        }
}

然后是saveBitmap和getImageUri methods.returning点击图片路径。

public void saveBitmap(Bitmap bmp) {
    String _time = "";
    Calendar cal = Calendar.getInstance();
    int millisecond = cal.get(Calendar.MILLISECOND);
    int second = cal.get(Calendar.SECOND);
    int minute = cal.get(Calendar.MINUTE);
    int hourofday = cal.get(Calendar.HOUR_OF_DAY);
    _time = "image_" + hourofday + "" + minute + "" + second + ""
            + millisecond + ".png";
    resultPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/pictures";
    try {
        File dir = new File(resultPath);
        if (!dir.exists())
            dir.mkdirs();
        File file = new File(dir, _time);
        FileOutputStream fOut = new FileOutputStream(file);

        fOut.flush();

        fOut.close();
        Toast.makeText(getApplicationContext(),
                "Image has been saved in KidsPainting folder",
                Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        Log.e("error in saving image", e.getMessage());
    }
}

public Uri getImageUri(Context inContext, Bitmap inImage) {


    ByteArrayOutputStream bytes = new ByteArrayOutputStream();

    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);

    return Uri.parse(path);
}

0 个答案:

没有答案