ma1co / OpenMemories-Framework

Build Android apps for your favorite Sony camera
MIT License
236 stars 35 forks source link

Access photos #11

Open jbieler opened 7 years ago

jbieler commented 7 years ago

Does anybody have a knowledge about how to access photos?

I'm looking into PMCA Demo right now, but it's very cryptic :)?

Any other places for working code?

lh8511 commented 7 years ago

PlaybackActivity in PMCADemo handles with photos from MediaLibrary, so take a look there. What is your goal to access photos?

jbieler commented 7 years ago

In the long run, it would be nice to have an abstraction that you can query to get the taken photos. But right now, I only the last photo that was taken.

How's that working?

Is Aviindexstore equivalent to the DSC1000 folder?

lh8511 commented 7 years ago

I think so. Try to use something like this to get last photo:

import com.sony.scalar.media.AvindexContentInfo; import com.sony.scalar.provider.AvindexStore; import android.content.Context; import android.database.Cursor; import android.net.Uri;

public static String getLastImage(Context context) {
    String imageFile = "";
    String imageDate = "";
    Uri baseUri = AvindexStore.Images.Media.getContentUri(AvindexStore.Images.Media.EXTERNAL_DEFAULT_MEDIA_ID);
    final String imageOrderBy = AvindexStore.Images.ImageColumns.CONTENT_CREATED_LOCAL_DATE_TIME + " DESC";
    Cursor imageCursor = context.getContentResolver().query(baseUri, AvindexStore.Images.Media.ALL_COLUMNS, null, null, imageOrderBy);
    if (imageCursor.moveToFirst()) {
        String imgData = imageCursor.getString(imageCursor.getColumnIndex(AvindexStore.Images.Media.DATA));
        AvindexContentInfo infoImage = AvindexStore.Images.Media.getImageInfo(imgData);
        imageFile = infoImage.getAttribute(AvindexContentInfo.TAG_DCF_TBL_FILE_NAME); // <-- last image filename
        imageDate = infoImage.getAttribute(AvindexContentInfo.TAG_DATETIME);
        String filenumber = imageCursor.getString(imageCursor.getColumnIndex(AvindexStore.Images.Media.DCF_FILE_NUMBER)); //<-- photo number
        imageCursor.close();
        //Toast.makeText(context.get.getBaseContext(), "[" + imageFile + "] | [" + imageDate + "]", Toast.LENGTH_SHORT).show();
    }
    return imageFile + ";" +imageDate;
}
ma1co commented 7 years ago

AvIndexStore is a content provider. Have a look here: https://developer.android.com/guide/topics/providers/content-provider-basics.html

jbieler commented 7 years ago

Thank you for the code piece.

Now that I know the filename. How do I access the image data? Do I create a File and read from it?

Will it work with RAW image or only jpegs?

I need the bitmap data...