Friday, 15 June 2012

Android - Bitmap.createScaledBitmap() setting Config to ARGB_8888 -


This was the first time I had a question that, despite the complete search, it has not been asked yet. / P>

I have a problem with Bitmap.createScaledBitmap () which results in enhanced bitmap always ARGB_8888 , regardless of configuration of input. Naturally, this is a problem while dealing with a limited problem.

  is InputStream; Try {is = mAssets.open ("test.png"); Bitmapfile Options = New Bitmap Feature. Option (); Opts.inPreferredConfig = Config.ARGB_4444; Bitmap default bitmap = bitmapfile Acodestream (is, empty, ops); System.out.println ("Basic Config:" + BasicBitMap.Get Config ()); MScale = (float) mHeight / originalBitmap.getHeight (); MBitmapScaled = Bitmap.createScaledBitmap (originalBitmap, (int) (mScale * (name) originalBitmap.getWidth ()), (int) (mScale * (name) originalBitmap.getHeight ()), true); System.out.println ("Scaled:" + mbitmapScaled.getConfig ()); OriginalBitmap.recycle (); is close(); } Hold (IOException e) {// something}   

returns the code output above:

Basic Bitmap: ARGB_4444

Scaled: ARGB_8888

As the bitmap.createScaledBitmap () method does not take a config, there seems to be no way to stop it. any idea?

createScaledBitmap (...) creates a new, extended bitmap and Therefore, in your given logic, the createBitmap (...) passes the method.

The following is the source code of the code ... Bitmap (...) :

  if (config! = Null) { Switch (config) {case RGB_565: newConfig = Config.RGB_565; break; Case ALPHA_8: Configure New Config =. LAPHA_8; break; // Nonspection Deception Case ARGB_4444: Case ARGB_8888: Default: newConfig = Config.ARGB_8888; break; }}   

with ARGB_4444 configuration changes every bitmap to a ARGB_8888 bitmap as you can see if your question To answer: No, there is no way to stop it (unless you want to copy parts of the source code and make your own scaling method).

Why Bitmap?

ARGB_4444 :

This field is deprecated. Due to poor quality of this configuration, instead of using ARGB_8888 is recommended.

No comments:

Post a Comment