4
在點擊它之前,我想使用選定的圖像設置按鈕的效果,然後單擊效果在ImageView中應用相同的圖像,但是它的方式是,使用默認圖像,而不是選擇的圖像。如何在ImageButton中單擊效果前設置圖像
imgView = (ImageView) findViewById(R.id.imgView);
btnSepia = (ImageButton) findViewById(R.id.btnSepia);
BitmapDrawable abmp = (BitmapDrawable) imgView.getDrawable();
bmp = abmp.getBitmap();
mProgress = (ProgressBar) findViewById(R.id.progressBar);
mProgress.setVisibility(View.INVISIBLE);
Intent i = new Intent(
Intent.ACTION_GET_CONTENT,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/");
startActivityForResult(i, RESULT_LOAD_IMAGE);
final Drawable resSepia = new BitmapDrawable(getResources(), bmp);
imgView.setImageDrawable(resSepia);
Handler handler = new Handler();
final Runnable r = new Runnable() {
@Override
public void run() {
if (resSepia == null)
return;
final ColorMatrix matrixA = new ColorMatrix();
// making image B&W
matrixA.setSaturation(0);
final ColorMatrix matrixB = new ColorMatrix();
// applying scales for RGB color values
matrixB.setScale(1f, .95f, .82f, 1.0f);
matrixA.setConcat(matrixB, matrixA);
final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrixA);
resSepia.setColorFilter(filter);
btnSepia.setImageDrawable(resSepia);
}
};
handler.postDelayed(r, 1000);
btnSepia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
imgView.setImageDrawable(resSepia);
}
});
Thanks();
對不起,我的英語不是我的母語。