位图位图= BitmapFactory.decodefile(文件名,选项);总是给空值

时间:2019-06-26 06:52:29

标签: android

该路径来自uri,并且该路径被拆分为.jpg文件,然后在给出解码文件位图时,其位图保持为空。

尝试添加option.injustsample = true; 然后尝试将其放入文件并获取位图 以为文件路径可能没有选择图像

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    try {

        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK) {
            if (requestCode == PICK_IMAGE) {
                //TODO: action
                Uri selectedImage = data.getData();
                path = getRealPathFromURI(selectedImage);
                path211.setText(path);
                Log.d(TAG, "Result image path from camera: "+path);


            }
        }
    }catch (Exception e ){

    }

}

private String getRealPathFromURI(Uri selectedImage) {
    String [] proj={MediaStore.Images.Media.DATA};
    Cursor cursor = managedQuery( selectedImage,
            proj, // Which columns to return
            null,       // WHERE clause; which rows to return (all rows)
            null,       // WHERE clause selection arguments (none)
            null); // Order-by clause (ascending by name)
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();

    String res = cursor.getString(column_index);

    cursor.close();

    return res;
}


int status = print.PrintImage(path);

public static int PrintImage(String path) {

    // *** getting bitmap of image from file

BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
//FileInputStream fis = new FileInputStream(file);
Bitmap bitmap = BitmapFactory.decodeFile(path,o);

位图必须具有文件位图,但我在位图中却为空

0 个答案:

没有答案