編輯:關於Android編程
1、獲取視頻縮略圖有兩個方法(1)通過內容提供器來獲取(2)人為創建縮略圖
(1)缺點就是必須更新媒體庫才能看到最新的視頻的縮略圖
[java]
復制代碼 代碼如下:
/**
* @param context
* @param cr
* @param Videopath
* @return
*/
public static Bitmap getVideoThumbnail(Context context, ContentResolver cr, String Videopath) {
ContentResolver testcr = context.getContentResolver();
String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, };
String whereClause = MediaStore.Video.Media.DATA + " = '" + Videopath + "'";
Cursor cursor = testcr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, whereClause,
null, null);
int _id = 0;
String videoPath = "";
if (cursor == null || cursor.getCount() == 0) {
return null;
}
if (cursor.moveToFirst()) {
int _idColumn = cursor.getColumnIndex(MediaStore.Video.Media._ID);
int _dataColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
do {
_id = cursor.getInt(_idColumn);
videoPath = cursor.getString(_dataColumn);
} while (cursor.moveToNext());
}
cursor.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND,
options);
return bitmap;
}
/**
* @param context
* @param cr
* @param Videopath
* @return
*/
public static Bitmap getVideoThumbnail(Context context, ContentResolver cr, String Videopath) {
ContentResolver testcr = context.getContentResolver();
String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, };
String whereClause = MediaStore.Video.Media.DATA + " = '" + Videopath + "'";
Cursor cursor = testcr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, whereClause,
null, null);
int _id = 0;
String videoPath = "";
if (cursor == null || cursor.getCount() == 0) {
return null;
}
if (cursor.moveToFirst()) {
int _idColumn = cursor.getColumnIndex(MediaStore.Video.Media._ID);
int _dataColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
do {
_id = cursor.getInt(_idColumn);
videoPath = cursor.getString(_dataColumn);
} while (cursor.moveToNext());
}
cursor.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND,
options);
return bitmap;
}(2)人為創建縮略圖要耗費一點時間
[java]
復制代碼 代碼如下:
/**
* 獲取視頻縮略圖
* @param videoPath
* @param width
* @param height
* @param kind
* @return
*/
private Bitmap getVideoThumbnail(String videoPath, int width , int height, int kind){
Bitmap bitmap = null;
bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, kind);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
/**
* 獲取視頻縮略圖
* @param videoPath
* @param width
* @param height
* @param kind
* @return
*/
private Bitmap getVideoThumbnail(String videoPath, int width , int height, int kind){
Bitmap bitmap = null;
bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, kind);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
2、圖片縮略圖
[java]
復制代碼 代碼如下:
/**
*
* @param context
* @param cr
* @param Imagepath
* @return
*/
public static Bitmap getImageThumbnail(Context context, ContentResolver cr, String Imagepath) {
ContentResolver testcr = context.getContentResolver();
String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, };
String whereClause = MediaStore.Images.Media.DATA + " = '" + Imagepath + "'";
Cursor cursor = testcr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, whereClause,
null, null);
int _id = 0;
String imagePath = "";
if (cursor == null || cursor.getCount() == 0) {
return null;
}
if (cursor.moveToFirst()) {
int _idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
int _dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
do {
_id = cursor.getInt(_idColumn);
imagePath = cursor.getString(_dataColumn);
} while (cursor.moveToNext());
}
cursor.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND,
options);
return bitmap;
}
/**
*
* @param context
* @param cr
* @param Imagepath
* @return
*/
public static Bitmap getImageThumbnail(Context context, ContentResolver cr, String Imagepath) {
ContentResolver testcr = context.getContentResolver();
String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, };
String whereClause = MediaStore.Images.Media.DATA + " = '" + Imagepath + "'";
Cursor cursor = testcr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, whereClause,
null, null);
int _id = 0;
String imagePath = "";
if (cursor == null || cursor.getCount() == 0) {
return null;
}
if (cursor.moveToFirst()) {
int _idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
int _dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
do {
_id = cursor.getInt(_idColumn);
imagePath = cursor.getString(_dataColumn);
} while (cursor.moveToNext());
}
cursor.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND,
options);
return bitmap;
}
在Android開發中,View是我們必須要接觸的用來展示的技術.通常情況下隨著View視圖的越來越復雜,整體布局的性能也會隨之下降.這裡介紹一個在某些場景下提升布局性能
前言昨日,公司討論用什麼工具來統計Crash信息時,有提出友盟,TalkingData,Crashlytics等等工具。鑒於之前其他兄弟部門有使用Crashlytics和
Android切圖注意事項 1. 切圖需要兩套分辨率的圖:480*800,720*1280。分被放在不同的文件夾中,同一張圖片,在兩個文件夾中的名字要一致。 2.
Android四大組件簡介請簡要介紹Android的四大組件。答案:Android系統有四種組件,這四種組件構成了Android應用的框架,然後由Intent聯系這四種組