Android 小笔记 Uri获取绝对路径 、路径转Bitmap、获取屏幕截图
2017-04-22 12:50
681 查看
1. Uri获取绝对路径
public static String getRealPathFromURI(Context mContext, Uri contentUri) {
String res = null;
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = mContext.getContentResolver().query(contentUri, proj, null, null, null);
if (cursor.moveToFirst()) {
;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}
2. 路径转Bitmap
//通过路径将图片转化为Bitmap
public static Bitmap GetBitmap(String path, int w, int h) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.decodeFile(path, opts);
int width = opts.outWidth;
int height = opts.outHeight;
float scaleWidth = 0.f, scaleHeight = 0.f;
if (width > w || height > h) {
scaleWidth = ((float) width) / w;
scaleHeight = ((float) height) / h;
}
opts.inJustDecodeBounds = false;
float scale = Math.max(scaleWidth, scaleHeight);
opts.inSampleSize = (int) scale;
WeakReference<Bitmap> weak = new WeakReference<Bitmap>(
BitmapFactory.decodeFile(path, opts));
return Bitmap.createScaledBitmap(weak.get(), w, h, true);
}
3.获取屏幕截图(此为获取全部屏幕)
public static Bitmap snapShotWithStatusBar(Activity activity)
{
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
int width = getScreenWidth(activity);
int height = getScreenHeight(activity);
Bitmap bp = null;
bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
view.destroyDrawingCache();
return bp;
}
public static String getRealPathFromURI(Context mContext, Uri contentUri) {
String res = null;
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = mContext.getContentResolver().query(contentUri, proj, null, null, null);
if (cursor.moveToFirst()) {
;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}
2. 路径转Bitmap
//通过路径将图片转化为Bitmap
public static Bitmap GetBitmap(String path, int w, int h) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.decodeFile(path, opts);
int width = opts.outWidth;
int height = opts.outHeight;
float scaleWidth = 0.f, scaleHeight = 0.f;
if (width > w || height > h) {
scaleWidth = ((float) width) / w;
scaleHeight = ((float) height) / h;
}
opts.inJustDecodeBounds = false;
float scale = Math.max(scaleWidth, scaleHeight);
opts.inSampleSize = (int) scale;
WeakReference<Bitmap> weak = new WeakReference<Bitmap>(
BitmapFactory.decodeFile(path, opts));
return Bitmap.createScaledBitmap(weak.get(), w, h, true);
}
3.获取屏幕截图(此为获取全部屏幕)
public static Bitmap snapShotWithStatusBar(Activity activity)
{
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
int width = getScreenWidth(activity);
int height = getScreenHeight(activity);
Bitmap bp = null;
bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
view.destroyDrawingCache();
return bp;
}
相关文章推荐
- Android获取URI的绝对路径的类
- android根据uri或文件绝对路径获取文件基本信息
- android根据uri或文件绝对路径获取文件基本信息
- Android根据图片Uri获取图片绝对路径
- android系统通过图片绝对路径获取URI的三种方法
- android系统通过图片绝对路径获取URI的三种方法
- android系统通过图片绝对路径获取URI的三种方法
- android 通过图片的uri来获取图片的绝对路径
- Android 获取屏幕截图 和保存到本地的sd卡路径下
- Android根据图片Uri获取图片绝对路径
- Android根据图片Uri获取图片绝对路径
- android系统通过图片绝对路径获取URI的三种方法
- 老马的技术博客 android系统通过图片绝对路径获取URI的三种方法
- Android获取drawable目录下的图片绝对路径并转为Bitmap
- Android 学习笔记十三 通过绝对路径得到uri
- android 根据Uri获取文件绝对路径
- android系统通过图片绝对路径获取URI的三种方法
- Android 获取屏幕截图 和保存到本地的sd卡路径下
- android调用自带文件选择器获取指定文件,编写解析Uri获取文件绝对路径
- Android根据URI获取图片绝对路径