80,354
社区成员
发帖
与我相关
我的任务
分享
if (data != null)
{
//取得返回的Uri,基本上选择照片的时候返回的是以Uri形式,但是在拍照中有得机子呢Uri是空的
Uri mImageCaptureUri = data.getData();
if (mImageCaptureUri != null)
{
// 取得图片的绝对路径
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(mImageCaptureUri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picPath = cursor.getString(columnIndex); // 图片的绝对路径
cursor.close();
// 打印路径
android.util.Log.e("绝对路径:",picPath);
try
{
//这个方法是根据Uri获取Bitmap图片的静态方法
Bitmap image = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageCaptureUri);
if (image != null)
{
android.util.Log.e("path",":"+data);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
//如果为空,那么我们就进行下面的方式获取
//能获取到Bitmap,但无论如何无法取得图片路径?????
else
{
Bundle extras = data.getExtras();
if (extras != null)
{
//这里是有些拍照后的图片是直接存放到Bundle中的所以我们可以从这里面获取Bitmap图片
Bitmap image = extras.getParcelable("data");
if (image != null)
{
android.util.Log.e("path without data",":"+data);
}
}
}
}
理论上是这样在的,Bitmap应该有个属性就是绝对路径,但我不知道应该怎么获取?? 既然能获得Bitmap了,路径应该就知道了吧,不然去哪里找那张图片的资源呢
private static Bitmap createBitmap(int width, int height, Config config, boolean hasAlpha) {
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("width and height must be > 0");
}
Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
if (config == Config.ARGB_8888 && !hasAlpha) {
bm.eraseColor(0xff000000);
nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha);
} else {
bm.eraseColor(0);
}
return bm;
}
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height,
Matrix m, boolean filter) {
checkXYSign(x, y);
checkWidthHeight(width, height);
if (x + width > source.getWidth()) {
throw new IllegalArgumentException("x + width must be <= bitmap.width()");
}
if (y + height > source.getHeight()) {
throw new IllegalArgumentException("y + height must be <= bitmap.height()");
}
// check if we can just return our argument unchanged
if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() &&
height == source.getHeight() && (m == null || m.isIdentity())) {
return source;
}
int neww = width;
int newh = height;
Canvas canvas = new Canvas();
Bitmap bitmap;
Paint paint;
Rect srcR = new Rect(x, y, x + width, y + height);
RectF dstR = new RectF(0, 0, width, height);
Config newConfig = Config.ARGB_8888;
final Config config = source.getConfig();
// GIF files generate null configs, assume ARGB_8888
if (config != null) {
switch (config) {
case RGB_565:
newConfig = Config.RGB_565;
break;
case ALPHA_8:
newConfig = Config.ALPHA_8;
break;
//noinspection deprecation
case ARGB_4444:
case ARGB_8888:
default:
newConfig = Config.ARGB_8888;
break;
}
}
if (m == null || m.isIdentity()) {
bitmap = createBitmap(neww, newh, newConfig, source.hasAlpha());
paint = null; // not needed
} else {
final boolean transformed = !m.rectStaysRect();
RectF deviceR = new RectF();
m.mapRect(deviceR, dstR);
neww = Math.round(deviceR.width());
newh = Math.round(deviceR.height());
bitmap = createBitmap(neww, newh, transformed ? Config.ARGB_8888 : newConfig,
transformed || source.hasAlpha());
canvas.translate(-deviceR.left, -deviceR.top);
canvas.concat(m);
paint = new Paint();
paint.setFilterBitmap(filter);
if (transformed) {
paint.setAntiAlias(true);
}
}
// The new bitmap was created from a known bitmap source so assume that
// they use the same density
bitmap.mDensity = source.mDensity;
canvas.setBitmap(bitmap);
canvas.drawBitmap(source, srcR, dstR, paint);
canvas.setBitmap(null);
return bitmap;
}
既然能获得Bitmap了,路径应该就知道了吧,不然去哪里找那张图片的资源呢
你说Bitmap这个类啊,这个类去读取路径?Bitmap有个getConfig()好像可以获得,,,
content,去读取content中的图片存储数据库,找到位置,,