i want to check orientation of an image so i found some code but it doesn't work because cursor is always null. My code is
File f = createImageFile(bitmap);
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = context.getContentResolver().query(Uri.parse(f.toString()), orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
private static File createImageFile(Bitmap bitmap) {
//create a file to write bitmap data
String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath();
File f = new File(fullPath, "image"+ System.currentTimeMillis()+".jpg");
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//Convert bitmap to byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (bitmap != null) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100 /*ignored for PNG*/, bos);
}
byte[] bitmapdata = bos.toByteArray();
//write the bytes in file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
return f;
}
But cur always returns null.I searched for converting file to uri so i found two methods Uri.parse(f.toString() and Uri.fromFile(f) but none has worked.