I want to convert a Drawable into a GrayScale Drawable (the exact same
content but gray).  BUt when I display both next to each other in a
GridView, the sizes are different...

I do this usig the following method:

public static Drawable createGrayScaleDrawable(Drawable drawable) {
                Bitmap colorBitmap = ((BitmapDrawable) drawable).getBitmap();

                // Bitmap.Config.RGB_8888 to preserve the alpha-channel
                Bitmap grayscaleBitmap = 
Bitmap.createBitmap(colorBitmap.getWidth(),
colorBitmap.getHeight(), Bitmap.Config.ARGB_8888);

                Canvas c = new Canvas(grayscaleBitmap);
                Paint p = new Paint();
                ColorMatrix cm = new ColorMatrix();

                cm.setSaturation(0);
                ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm);
                p.setColorFilter(filter);
                c.drawBitmap(colorBitmap, 0, 0, p);

                Drawable grayscaleDrawable = new 
BitmapDrawable(grayscaleBitmap);

                return grayscaleDrawable;
        }

When I now display them both next to each other in a GridView. In the
GridView Adapter I create Buttons using the following code:
                Button button = new Button(context, null,
R.style.DashboardButton);
                button.setCompoundDrawablesWithIntrinsicBounds(null,
dashboardButton.getDrawable(), null, null); //either the gray or
original one
                button.setText(dashboardButton.getText());
                button.setOnClickListener(dashboardButton.getOnclickListener());
                button.setGravity(Gravity.CENTER_HORIZONTAL);


Does anyone know why this is happening?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to