本文整理汇总了Java中android.provider.MediaStore.Images.ImageColumns类的典型用法代码示例。如果您正苦于以下问题:Java ImageColumns类的具体用法?Java ImageColumns怎么用?Java ImageColumns使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImageColumns类属于android.provider.MediaStore.Images包,在下文中一共展示了ImageColumns类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryOrientationForImage
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
protected int queryOrientationForImage(long id, CancellationSignal signal) {
final ContentResolver resolver = getContext().getContentResolver();
Cursor cursor = null;
try {
cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
ImageOrientationQuery.PROJECTION, ImageColumns._ID + "=" + id, null, null);
if (cursor.moveToFirst()) {
return cursor.getInt(ImageOrientationQuery.ORIENTATION);
} else {
Log.w(TAG, "Missing orientation data for " + id);
return 0;
}
} finally {
IoUtils.closeQuietly(cursor);
}
}
示例2: getRealFilePath
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/**
* Try to return the absolute file path from the given Uri
*
* @param context
* @param uri
* @return the file path or null
*/
public static String getRealFilePath( final Context context, final Uri uri ) {
if ( null == uri ) return null;
final String scheme = uri.getScheme();
String data = null;
if ( scheme == null )
data = uri.getPath();
else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
data = uri.getPath();
} else if ( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) {
Cursor cursor = context.getContentResolver().query( uri, new String[] { ImageColumns.DATA }, null, null, null );
if ( null != cursor ) {
if ( cursor.moveToFirst() ) {
int index = cursor.getColumnIndex( ImageColumns.DATA );
if ( index > -1 ) {
data = cursor.getString( index );
}
}
cursor.close();
}
}
return data;
}
示例3: getRealFilePath
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/** 根据Uri获取图片文件的绝对路径 */
public static String getRealFilePath(Context context, Uri uri) {
if (null == uri) {
return null;
}
final String scheme = uri.getScheme();
String data = null;
if (scheme == null) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null, null);
if (null != cursor) {
if (cursor.moveToFirst()) {
int index = cursor.getColumnIndex(ImageColumns.DATA);
if (index > -1) {
data = cursor.getString(index);
}
}
cursor.close();
}
}
return data;
}
示例4: photosCursorToSelection
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
public static PhotoUpload photosCursorToSelection(Uri contentUri,
Cursor cursor) {
PhotoUpload item = null;
try {
File file = new File(cursor.getString(cursor
.getColumnIndexOrThrow(ImageColumns.DATA)));
if (file.exists()) {
item = PhotoUpload
.getSelection(contentUri, cursor.getInt(cursor
.getColumnIndexOrThrow(ImageColumns._ID)));
}
} catch (Exception e) {
e.printStackTrace();
}
return item;
}
示例5: getCurrent
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/**
* 获取最近使用的照片
*
* @return
*/
public List<PhotoModel> getCurrent() {
Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
ImageColumns.DATA,
ImageColumns.DATE_ADDED, ImageColumns.SIZE
}, null, null, ImageColumns.DATE_ADDED);
if (cursor == null || !cursor.moveToNext())
return new ArrayList<PhotoModel>();
List<PhotoModel> photos = new ArrayList<PhotoModel>();
cursor.moveToLast();
do {
if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
PhotoModel photoModel = new PhotoModel();
photoModel.setOriginalPath(cursor.getString(cursor
.getColumnIndex(ImageColumns.DATA)));
photos.add(photoModel);
}
} while (cursor.moveToPrevious());
IOUtils.closeQuietly(cursor);
return photos;
}
示例6: getAlbum
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/**
* 获取某个相册中的所有图片
*
* @param name
* @return
*/
public List<PhotoModel> getAlbum(String name) {
Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
ImageColumns.BUCKET_DISPLAY_NAME,
ImageColumns.DATA, ImageColumns.DATE_ADDED, ImageColumns.SIZE
}, "bucket_display_name = ?",
new String[] {
name
}, ImageColumns.DATE_ADDED);
if (cursor == null || !cursor.moveToNext())
return new ArrayList<PhotoModel>();
List<PhotoModel> photos = new ArrayList<PhotoModel>();
cursor.moveToLast();
do {
if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
PhotoModel photoModel = new PhotoModel();
photoModel.setOriginalPath(cursor.getString(cursor
.getColumnIndex(ImageColumns.DATA)));
photos.add(photoModel);
}
} while (cursor.moveToPrevious());
IOUtils.closeQuietly(cursor);
return photos;
}
示例7: getContentValuesForData
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
public static ContentValues getContentValuesForData(String title,
long date, Location location, int orientation, long jpegLength,
String path, int width, int height, String mimeType) {
File file = new File(path);
long dateModifiedSeconds = TimeUnit.MILLISECONDS.toSeconds(file.lastModified());
ContentValues values = new ContentValues(11);
values.put(ImageColumns.TITLE, title);
values.put(ImageColumns.DISPLAY_NAME, title + JPEG_POSTFIX);
values.put(ImageColumns.DATE_TAKEN, date);
values.put(ImageColumns.MIME_TYPE, mimeType);
values.put(ImageColumns.DATE_MODIFIED, dateModifiedSeconds);
// Clockwise rotation in degrees. 0, 90, 180, or 270.
values.put(ImageColumns.ORIENTATION, orientation);
values.put(ImageColumns.DATA, path);
values.put(ImageColumns.SIZE, jpegLength);
setImageSize(values, width, height);
if (location != null) {
values.put(ImageColumns.LATITUDE, location.getLatitude());
values.put(ImageColumns.LONGITUDE, location.getLongitude());
}
return values;
}
示例8: getMimeTypeForMedia
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
public static String getMimeTypeForMedia(ContentResolver cr, int id,
boolean isImage) {
Cursor cursor;
if(isImage)
cursor = cr.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String [] {MediaStore.Images.Media.MIME_TYPE}, ImageColumns._ID+" = ?",
new String [] { String.valueOf(id) }, null);
else
cursor = cr.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
new String [] {MediaStore.Video.Media.MIME_TYPE}, VideoColumns._ID+" = ?",
new String [] { String.valueOf(id) }, null);
try {
if(!cursor.moveToFirst())
return null;
return cursor.getString(0);
}
finally {
cursor.close();
}
}
示例9: getDataFilepathForMedia
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
public static String getDataFilepathForMedia(ContentResolver cr, int id, boolean isImage)
{
Cursor cursor;
if(isImage)
cursor = cr.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String [] {MediaStore.Images.Media.DATA}, ImageColumns._ID+" = ?",
new String [] { String.valueOf(id) }, null);
else
cursor = cr.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
new String [] {MediaStore.Video.Media.DATA}, VideoColumns._ID+" = ?",
new String [] { String.valueOf(id) }, null);
try {
if(!cursor.moveToFirst())
return null;
return cursor.getString(0);
}
finally {
cursor.close();
}
}
示例10: LocalAlbum
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
public LocalAlbum(Path path, GalleryApp application, int bucketId,
boolean isImage, String name) {
super(path, nextVersionNumber());
mApplication = application;
mResolver = application.getContentResolver();
mBucketId = bucketId;
mName = name;
mIsImage = isImage;
if (isImage) {
mWhereClause = ImageColumns.BUCKET_ID + " = ?";
mOrderClause = ImageColumns.DATE_TAKEN + " DESC, "
+ ImageColumns._ID + " DESC";
mBaseUri = Images.Media.EXTERNAL_CONTENT_URI;
mProjection = LocalImage.PROJECTION;
mItemPath = LocalImage.ITEM_PATH;
} else {
mWhereClause = VideoColumns.BUCKET_ID + " = ?";
mOrderClause = VideoColumns.DATE_TAKEN + " DESC, "
+ VideoColumns._ID + " DESC";
mBaseUri = Video.Media.EXTERNAL_CONTENT_URI;
mProjection = LocalVideo.PROJECTION;
mItemPath = LocalVideo.ITEM_PATH;
}
mNotifier = new ChangeNotifier(this, mBaseUri, application);
}
示例11: getTrueFilename
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/**
* Gets the actual filename for a Uri from Gallery's ContentProvider.
*/
private static String getTrueFilename(Context context, Uri src) {
if (context == null || src == null) {
return null;
}
final String[] trueName = new String[1];
querySource(context, src, new String[] {
ImageColumns.DATA
}, new ContentResolverQueryCallback() {
@Override
public void onCursorResult(Cursor cursor) {
trueName[0] = new File(cursor.getString(0)).getName();
}
});
return trueName[0];
}
示例12: getContentValues
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
private static ContentValues getContentValues(Context context, Uri sourceUri,
File file, long time) {
final ContentValues values = new ContentValues();
time /= 1000;
values.put(Images.Media.TITLE, file.getName());
values.put(Images.Media.DISPLAY_NAME, file.getName());
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Images.Media.DATE_TAKEN, time);
values.put(Images.Media.DATE_MODIFIED, time);
values.put(Images.Media.DATE_ADDED, time);
values.put(Images.Media.ORIENTATION, 0);
values.put(Images.Media.DATA, file.getAbsolutePath());
values.put(Images.Media.SIZE, file.length());
final String[] projection = new String[] {
ImageColumns.DATE_TAKEN,
ImageColumns.LATITUDE, ImageColumns.LONGITUDE,
};
SaveImage.querySource(context, sourceUri, projection,
new ContentResolverQueryCallback() {
@Override
public void onCursorResult(Cursor cursor) {
values.put(Images.Media.DATE_TAKEN, cursor.getLong(0));
double latitude = cursor.getDouble(1);
double longitude = cursor.getDouble(2);
// TODO: Change || to && after the default location
// issue is fixed.
if ((latitude != 0f) || (longitude != 0f)) {
values.put(Images.Media.LATITUDE, latitude);
values.put(Images.Media.LONGITUDE, longitude);
}
}
});
return values;
}
示例13: getCurrent
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/** 获取最近照片列表 */
public List<PhotoModel> getCurrent() {
Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] { ImageColumns.DATA,
ImageColumns.DATE_ADDED, ImageColumns.SIZE }, null, null, ImageColumns.DATE_ADDED);
if (cursor == null || !cursor.moveToNext())
return new ArrayList<PhotoModel>();
List<PhotoModel> photos = new ArrayList<PhotoModel>();
cursor.moveToLast();
do {
if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
PhotoModel photoModel = new PhotoModel();
photoModel.setOriginalPath(cursor.getString(cursor.getColumnIndex(ImageColumns.DATA)));
photos.add(photoModel);
}
} while (cursor.moveToPrevious());
return photos;
}
示例14: getAlbum
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/** 获取对应相册下的照片 */
public List<PhotoModel> getAlbum(String name) {
Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] { ImageColumns.BUCKET_DISPLAY_NAME,
ImageColumns.DATA, ImageColumns.DATE_ADDED, ImageColumns.SIZE }, "bucket_display_name = ?",
new String[] { name }, ImageColumns.DATE_ADDED);
if (cursor == null || !cursor.moveToNext())
return new ArrayList<PhotoModel>();
List<PhotoModel> photos = new ArrayList<PhotoModel>();
cursor.moveToLast();
do {
if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
PhotoModel photoModel = new PhotoModel();
photoModel.setOriginalPath(cursor.getString(cursor.getColumnIndex(ImageColumns.DATA)));
photos.add(photoModel);
}
} while (cursor.moveToPrevious());
return photos;
}
示例15: getRealFilePath
import android.provider.MediaStore.Images.ImageColumns; //导入依赖的package包/类
/**
* 获取图片的存储路径;
*
* @param context
* @param uri
* @return
*/
public static String getRealFilePath(Context context, Uri uri) {
if (null == uri)
return null;
String scheme = uri.getScheme();
String data = null;
if (scheme == null)
data = uri.getPath();
else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null,
null);
if (null != cursor) {
if (cursor.moveToFirst()) {
int index = cursor.getColumnIndex(ImageColumns.DATA);
if (index > -1) {
data = cursor.getString(index);
}
}
cursor.close();
}
}
return data;
}