2012-03-04 22 views
5

Tengo ImageView generado en XML-Layout y quiero copiar la imagen en la que hago clic LinearLayout a continuación.¿Por qué Bitmap.getConfig() devuelve nulo?

tuve asignar el evento de seguimiento de todos los eventos del onClickImageView 's:

public void onClick(View v) { 
    // Take layout where i want to put my copy-image 
    LinearLayout savingLayout = (LinearLayout)findViewById(R.id.linearSaved); 

    //Create a new image 
    ImageView savedImage = new ImageView(savingLayout.getContext()); 
    //Take the bitmap from the object i clicked 
    Bitmap b = ((BitmapDrawable)((ImageView)v).getDrawable()).getBitmap(); 
    //Take the config of the bitmap. IT RETURNS NULL 
    Bitmap.Config cfg= b.getConfig(); 
    //Copy the Bitmap and assign it to the new ImageView... IT CRASH (cfg == null) 
    Bitmap b2 = b.copy(cfg, true); 
    savedImage.setImageBitmap(b2); 
    savingLayout.addView(savedImage); 
} 

Entonces, ¿por b.getConfig() vuelve nula? Hay una solución?

Gracias

Respuesta

1

Use Bitmap.Config.ARGB_8888 en lugar de b.getConfig() como una solución.

+1

El 'getConfig' no está allí porque su resultado depende del tipo de imagen y/o dispositivo que tengo? – zambotn

Cuestiones relacionadas