2017-11-29 9 views
0

カラーコードが#AAA28B(170R、162G、139B)の画像が1つあります。今現在の画像のサイズが1200x1200だとしましょう。今度は600x600でスケールダウンしたいので、コードの下でビットマップを使用しますが、問題は#ABA38Cのビットマップカラーコードを変更することです。これを防ぐ方法は?(171R、163G、140B)になります。ビットマップカラーコード変更後のスケールダウン

スクリーンショットを添付してください。最初のイメージは、アンドロイドドロワブルから直接ロードされ、次のコードを使用してロードされます。ここで

private void loadImage(int width, int height){ 

     Bitmap bitMapTest=BitmapFactory.decodeResource(getResources(),R.drawable.ic_test); 

     Log.i("IMAGE","Image format is"+ bitMapTest.getConfig().name()+ 
       "Image size is"+ bitMapTest.hasAlpha() + "bitmap size is"+ bitMapTest.getHeight()); 


     Bitmap decodeBitmap=decodeSampledBitmapFromResource(getResources(),R.drawable.ic_test,width,height); 
     Log.i("IMAGE","Image format is"+ decodeBitmap.getConfig().name()+ 
       "Image size is"+ decodeBitmap.hasAlpha() + "bitmap size is"+ decodeBitmap.getHeight()); 

     //adjust of alha deos not give me any help result remain same 
     //decodeBitmap=adjustOpacity(decodeBitmap); 

     mImgView.setImageBitmap(decodeBitmap); 

    } 

    public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, 
                 int reqWidth, int reqHeight) { 

     // First decode with inJustDecodeBounds=true to check dimensions 
     final BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     options.inPreferredConfig= Bitmap.Config.ARGB_8888; 
     options.inScaled=false; 
     BitmapFactory.decodeResource(res, resId, options); 

     // Calculate inSampleSize 
     options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 

     // Decode bitmap with inSampleSize set 
     options.inJustDecodeBounds = false; 
     return BitmapFactory.decodeResource(res, resId, options); 
    } 

    public static int calculateInSampleSize(
      BitmapFactory.Options options, int reqWidth, int reqHeight) { 
     // Raw height and width of image 
     final int height = options.outHeight; 
     final int width = options.outWidth; 
     int inSampleSize = 2; 

     if (height > reqHeight || width > reqWidth) { 

      final int halfHeight = height/2; 
      final int halfWidth = width/2; 

      // Calculate the largest inSampleSize value that is a power of 2 and keeps both 
      // height and width larger than the requested height and width. 
      while ((halfHeight/inSampleSize) >= reqHeight 
        && (halfWidth/inSampleSize) >= reqWidth) { 
       inSampleSize *= 2; 
      } 
     } 

     return inSampleSize; 
    } 

をオリジナルの画像です: -

Here is solid color image which i need to scale down

+0

ビットマップはどのようにカラーコードを持つことができますか?ピクセルにはカラーコードがあります。 – greenapps

+0

私は完全に色のイメージを持っています。私はその待ちを分かりましょう – Herry

+0

'decodeBitmap = adjustOpacity(decodeBitmap);'。なしで試してください。 – greenapps

答えて

0

それはthisのようなベタ画像の罰金働いてスケールダウンのために、次のコードを適用するように思えます。

Bitmap decodeBitmap=Bitmap.createScaledBitmap(sourceBitmap,width,height,false/*Make sure filter is false*/); 
関連する問題