簡體   English   中英

Android Camera將圖像返回為人像,使其變為風景?

[英]Android Camera returns image as Portrait, getting it as landscape?

 Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

        i.putExtra(MediaStore.EXTRA_OUTPUT, MyFileContentProvider.CONTENT_URI);

        startActivityForResult(i, CAMERA_RESULT);

這就是我在應用程序中調用照相機的方式,並且由於我需要高質量的輸出,因此我在兩者之間使用了contentProvider

Bitmap mBitmap = BitmapFactory.decodeFile(out.getAbsolutePath());

        ImageView im1 = (ImageView)findViewById(R.id.camTemp);
        im1.setImageBitmap(mBitmap);

onActivityResult() ,這就是我顯示拍攝圖像的方式。

在這之間,這是contentProvider類的代碼。

public class MyFileContentProvider extends ContentProvider {
public static final Uri CONTENT_URI = Uri.parse
        ("content://obx.com.futurister/");
private static final HashMap<String, String> MIME_TYPES =
        new HashMap<String, String>();

static {
    MIME_TYPES.put(".jpg", "image/jpeg");
    MIME_TYPES.put(".jpeg", "image/jpeg");
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    // Implement this to handle requests to delete one or more rows.
    throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public String getType(Uri uri) {
    String path = uri.toString();

    for (String extension : MIME_TYPES.keySet()) {
        if (path.endsWith(extension)) {
            return (MIME_TYPES.get(extension));
        }
    }
    return (null);
}

@Override
public Uri insert(Uri uri, ContentValues values) {
    // TODO: Implement this to handle requests to insert a new row.
    throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public boolean onCreate() {
    try {
        File mFile = new File(getContext().getFilesDir(), "newImage.jpg");
        if(!mFile.exists()) {
            mFile.createNewFile();
        }
        getContext().getContentResolver().notifyChange(CONTENT_URI, null);
        return (true);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

}

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
        throws FileNotFoundException {

    File f = new File(getContext().getFilesDir(), "newImage.jpg");
    if (f.exists()) {
        return (ParcelFileDescriptor.open(f,
                ParcelFileDescriptor.MODE_READ_WRITE));
    }
    throw new FileNotFoundException(uri.getPath());
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    // TODO: Implement this to handle query requests from clients.
    throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public int update(Uri uri, ContentValues values, String selection,
                  String[] selectionArgs) {
    // TODO: Implement this to handle requests to update one or more rows.
    throw new UnsupportedOperationException("Not yet implemented");
}

}

現在的問題是,我最終在ImageView獲得的ImageViewportrait ,默認情況下如何將其獲取為landscape

您可以輕松旋轉人像圖像並獲得風景!

Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap , 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM