content,去读取content中的图片存储数据库,找到位置,,

解决方案 »

  1.   

    通过Bitmap参数去读取吗,敢用哪个方法呢??
      

  2.   

    你说Bitmap这个类啊,这个类去读取路径?Bitmap有个getConfig()好像可以获得,,,
      

  3.   

    我这是这样想的,其他人写的activity,获得的图片都是bitmap位图,传到我这个activity也是bitmap,但是我这个activity只能接受绝对路径作为参数进行处理。。
    所以就要求我这个activity首先根据接收到的bitmap位置得到绝对路径。。
    我该怎么写这个函数呢??完全没有思路啊。。
      

  4.   

    既然能获得Bitmap了,路径应该就知道了吧,不然去哪里找那张图片的资源呢
      

  5.   

    理论上是这样在的,Bitmap应该有个属性就是绝对路径,但我不知道应该怎么获取??
      

  6.   

    看下android source,Bitmap的图片位置应该包含在一个config里面,但是这是个封装实体,你获取不到,  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;
        }
      

  7.   

    我原来也做过类似需求,就是获取下载的图片,不过那些图片我都是写死了,就是手机安装apk后有对应得应用程序目录,也就是data/data下面那个,你可以通过代码获取得到你自己应用的绝对路径,在里面创建自己的目录,把下载,照相的图片放里面,这些都可以我们为用户定义的。到时候获取只要通过java提供的遍历该目录下的文件名和文件类型就可以获取到该目录下所有图片的绝对路径了。
      

  8.   

    我主要是拍照的时候,如果能获取到Uri是可以得到绝对路径的,但是有的拍照是将图片放到Bundle里面,没有Uri,就没办法了啊。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);
    }
         }
      }     }我原来也做过类似需求,就是获取下载的图片,不过那些图片我都是写死了,就是手机安装apk后有对应得应用程序目录,也就是data/data下面那个,你可以通过代码获取得到你自己应用的绝对路径,在里面创建自己的目录,把下载,照相的图片放里面,这些都可以我们为用户定义的。到时候获取只要通过java提供的遍历该目录下的文件名和文件类型就可以获取到该目录下所有图片的绝对路径了。