2012-03-12 13 views
1

私は、回転したファイル(0,90,180,270度)からビットマップをデコードする方法を探しています。画像が大きいと私はビットマップをデコードして、両方のビットマップがメモリ内にあると、メモリが不足する危険性がある瞬間がありビットマップを回転してデコードする

Bitmap rotatedBitmap=Bitmap.createBitmap(source, x, y, width, height, m, filter) 

のようなものを使用している場合であるので、私はそれを必要とします。

アイデア?ありがとう。

答えて

1

おそらくこれはあなたが探しているものですか?あなたはNDKベースのソリューションを使用したい場合

//decodes image and scales it to reduce memory consumption 
    //NOTE: if the image has dimensions which exceed int width and int height 
    //its dimensions will be altered. 
    private Bitmap decodeToLowResImage(byte [] b, int width, int height) { 
     try { 
      //Decode image size 
      BitmapFactory.Options o = new BitmapFactory.Options(); 
      o.inJustDecodeBounds = true; 
      BitmapFactory.decodeStream(new ByteArrayInputStream(b), null, o); 

      //The new size we want to scale to 
      final int REQUIRED_SIZE_WIDTH=(int)(width*0.7); 
      final int REQUIRED_SIZE_HEIGHT=(int)(height*0.7); 

      //Find the correct scale value. It should be the power of 2. 
      int width_tmp=o.outWidth, height_tmp=o.outHeight; 
      int scale=1; 
      while(true){ 
       if(width_tmp/2<REQUIRED_SIZE_WIDTH || height_tmp/2<REQUIRED_SIZE_HEIGHT) 
        break; 
       width_tmp/=2; 
       height_tmp/=2; 
       scale*=2; 
      } 

      //Decode with inSampleSize 
      BitmapFactory.Options o2 = new BitmapFactory.Options(); 
      o2.inSampleSize=scale; 
      return BitmapFactory.decodeStream(new ByteArrayInputStream(b), null, o2); 
     } catch (OutOfMemoryError e) { 
      //handle this 
     } 
     return null; 
    } 
+0

あなたの答えをありがとう、私はサイズを小さくしたい、ちょうどそれを回転させたくない – Addev

+0

イメージを回転させたい場合、ImageViewクラスを拡張し、onDrawメソッドをオーバーライドし、キャンバスを取得し、キャンバスを作成し、最終的にdrawable上でdrawメソッドを使用します。 –

0

、私は1つhereを作成しました、と私はgithubのプロジェクトhereを作りました。

これは、ネイティブC「世界」にデータを置くことによってOOMを避けるため、古いデータを再利用し、回転後、戻って結果を返します。

ダウンサンプリングを必要としません。

関連する問題