just a quick question. how do you get thumbnail images from an sdcard on HTC Desire HD. i have this code but it just shows a blank screen and a scroll. the images can be chosen but as i say, you can't see anything.
String [] img = {MediaStore.Images.Thumbnails._ID};
imageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img, null, null, MediaStore.Images.Thumbnails._ID);
image_column_index = imageCursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
if(imageCursor != null && imageCursor.moveToNext()) {
grid = (GridView)findViewById(R.id.gridview);
grid.setAdapter(new ImageAdapter(getApplicationContext()));
grid.setOnItemClickListener(this);
}
Here is the piece of code where its coming from. Any ideas what i can be doing wrong?.. by the way, the working on other devices like the G-1. Thank you.
Related
I'm building a Custom Control (a Gallery Picture Picker)
basically trying to re-make a this : Microsoft.Maui.Media.MediaPicker.PickPhotoAsync()
but i didn't find anyway to retrieve user pictures on MAUI ..
on Xamarin.Android i used this code :
var uriExternal = MediaStore.Images.Media.ExternalContentUri;
string[] projection = { (MediaStore.Images.Media.InterfaceConsts.Id),
(MediaStore.Images.Media.InterfaceConsts.DateAdded),
(MediaStore.Images.Media.InterfaceConsts.RelativePath) };
var cursor = Android.App.Application.Context.ContentResolver.Query(uriExternal, projection, null, null, MediaStore.Images.Media.InterfaceConsts.DateAdded);
if (cursor != null) {
int columnIndexID = cursor.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.Id);
int RelativePathID = cursor.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.RelativePath);
while (cursor.MoveToNext()) {
long imageId = cursor.GetLong(columnIndexID);
string rPath = cursor.GetString(RelativePathID);
//Get the Picture's URI
Android.Net.Uri uriImage = Android.Net.Uri.WithAppendedPath(uriExternal, "" + imageId);
...
}
}
with this Code, given the required permissions, i could get the external path of all pictures of an Android phone to then use them in my PicturePicking custom control ..
==> how can i do this in Microsoft MAUI !! (targeting Android & IOS)
(just to be clear, of course i know that i could just use MediaPicker's [PickPhotoAsync] function, but i clearly don't want that, it's not an option)
Thanks in advance for any help !
So after 2 days of searching.. i've came to the conclusion that the only way to do this is by using Plateform Specific Code ..
(i tryed it successfully)
I need to know the orientation of an image from the gallery (taken by the camera). My initial approach was to use MediaStore.Images.Media.ORIENTATION which was working for my Droid 1. While testing on the HTC Thunderbolt that phone only saves 0 to that field.
I then moved to reading the exif data:
ExifInterface exifReader = new ExifInterface(mFilePath);
exifReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
This also returns 0 for every image. Anyone have ideas on how to properly get the orientation of a photo take on android?
Here is the code I used onActivityResult() in my activity. The intent returned was for picking an image of the type image/*. Works well for me!
Uri imageUri = intent.getData();
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(imageUri, 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);
My solution:
Remove any checking for orientation from exif data. I could not find one instance where it was accurate.
Use the standard String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION}; to get an orientation.
If this is 0 use
decodeStream...
if(o.outHeight > o.outWidth){
//set orientation to portrait
}
else it is landscape
This is a bug i found that was related to another android bug.. I found a reasonable solution posted here https://stackoverflow.com/a/8864367/137404
I am making my first app, and there I have photos I want the user could make them bigger with a "zoom effect".
I have been searching about it in the web and I have found I must use a webview which can do that automatically.
But the image doesn't appear. I only can watch his route as a text: "file:///storage/sdcard0/postals/4249.jpg"
And it doesn't matter if I include "file://" or not.
Here it is the code. I hope anyone of you could help me.
"Ivpostal" is the name of my webview. And "adrecafoto" is an string with the route of the image in the galery of the phone:
**uriruta=Uri.parse(adrecafoto);
Cursor c = getContentResolver().query(uriruta,null,null,null,null);
c.moveToNext();
String filePath = "";
String[] column = { MediaStore.Images.Media.DATA };
int columnIndex = c.getColumnIndex(column[0]);
if (c.moveToFirst()) {
filePath = c.getString(columnIndex);
}
c.close();
String rutafoto= "file://"+filePath;
ivpostal.loadData(rutafoto, "text/html","utf-8");**
background
starting with jelly bean (4.1), android now supports contact images that are 720x720 .
before, starting with ICS (4.0), android has supported contact images that are 256x256.
and before that, contact photos had just a size of a thumbnail - 96x96
the question
is there any function in the API that returns the max size of the contact image?
i also hope that the manufacturers didn't change the max image sizes, and even if they did and we have such a function, it would return us the correct size.
according to this link, the correct way to get the max size is:
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static int getMaxContactPhotoSize(final Context context) {
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
// Note that this URI is safe to call on the UI thread.
final Uri uri = ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI;
final String[] projection = new String[] { ContactsContract.DisplayPhoto.DISPLAY_MAX_DIM };
final Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
try {
c.moveToFirst();
return c.getInt(0);
} finally {
c.close();
}
}
// fallback: 96x96 is the max contact photo size for pre-ICS versions
return 96;
}
EDIT: if we use at least API 16 (4.1), it's possible to use something like:
#AnyThread
#RequiresPermission(anyOf = [Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS])
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
fun getMaxContactPhotoSize(context: Context): Int {
// Note that this URI is safe to call on the UI thread.
if (contactMaxPhotoSize > 0)
return contactMaxPhotoSize
val uri = ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI
val projection = arrayOf(ContactsContract.DisplayPhoto.DISPLAY_MAX_DIM)
context.contentResolver.query(uri, projection, null, null, null)?.use { cursor ->
cursor.moveToFirst()
contactMaxPhotoSize = cursor.getInt(0)
}
if (contactMaxPhotoSize > 0)
return contactMaxPhotoSize
// fallback: 720x720 is the max contact photo size for 4.1 version
contactMaxPhotoSize = 720
return contactMaxPhotoSize
}
From the announcement:
With Android 4.1, you can store contact photos that are as large as 720 x 720, making contacts even richer and more personal. Apps can store and retrieve contact photos at that size or use any other size needed. The maximum photo size supported on specific devices may vary, so apps should query the built-in contacts provider at run time to obtain the max size for the current device.
I would query for ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI. It should return what you're looking for.
I need to know the orientation of an image from the gallery (taken by the camera). My initial approach was to use MediaStore.Images.Media.ORIENTATION which was working for my Droid 1. While testing on the HTC Thunderbolt that phone only saves 0 to that field.
I then moved to reading the exif data:
ExifInterface exifReader = new ExifInterface(mFilePath);
exifReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
This also returns 0 for every image. Anyone have ideas on how to properly get the orientation of a photo take on android?
Here is the code I used onActivityResult() in my activity. The intent returned was for picking an image of the type image/*. Works well for me!
Uri imageUri = intent.getData();
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(imageUri, 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);
My solution:
Remove any checking for orientation from exif data. I could not find one instance where it was accurate.
Use the standard String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION}; to get an orientation.
If this is 0 use
decodeStream...
if(o.outHeight > o.outWidth){
//set orientation to portrait
}
else it is landscape
This is a bug i found that was related to another android bug.. I found a reasonable solution posted here https://stackoverflow.com/a/8864367/137404