此代碼的工作! 在ImageView中設置新的位圖及其工作!
public class Bleach extends AppCompatActivity implements Cloneable {
Bitmap bm;
ImageButton bDone;
Bitmap _bitmapPrev;
Bitmap _bitmapCur;
File imageFile;
Bitmap bm3;
Bitmap bm4;
ImageView bl;
int x;
int y;
String[] projection = new String[]{
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.MIME_TYPE
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bleach);
bDone = (ImageButton) findViewById(R.id.donebtnid);
bDone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
startActivity(new Intent(Bleach.this, MainMenuActivity.class));
}
});
//bl = (ImageView)findViewById(R.id.pickbleachi d);
final Cursor cursor = getContentResolver()
.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
if (cursor != null) {
if (cursor.moveToFirst()) {
final ImageView bl = (ImageView) findViewById(R.id.pickbleachid);
String imageLocation = cursor.getString(1);
imageFile = new File(imageLocation);
if (imageFile.exists()) { // TODO: is there a better way to do this?
try{
bm = BitmapFactory.decodeFile(imageLocation);
bm3 = ExifUtil.rotateBitmap(imageLocation,bm);
}catch (Exception exception){
Log.d("PICtureConfirmation ","bm decodefile"+ exception.getMessage());
}
try {
// bl.setImageBitmap(bm3);
//Drawable imgDrawable = teeth.getDrawable();
//Bitmap bm5=((BitmapDrawable)bm3.getDrawable()).getBitmap();
int W = bm3.getWidth();
int H = bm3.getHeight();
int [][][] clr = new int [3][H][W];
int pixel;
for(int i=0;i<W;i++)
for(int j=0;j<H;j++){
pixel = bm3.getPixel(i, j);
clr[0][j][i] = Color.red(pixel+5);
clr[1][j][i] = Color.green(pixel+5);
clr[2][j][i] = Color.blue(pixel+5);
}
/*
...
pixel changging process
...
*/
//save a new image
for(int i=0;i<W;i++) {
for (int j = 0; j < H; j++) {
bm3.setPixel(i, j, Color.rgb(clr[0][j][i], clr[1][j][i], clr[2][j][i]));
}
}
bl.setImageBitmap(bm3);
}
catch (Exception e){}
}
}
}
}
public void SetGamma(double red,double green, double blue){
Bitmap temp = (Bitmap)_bitmapCur;
//Bitmap bmap = (Bitmap)temp.clone();
}
}
您的位圖應該是可變的,以便對其進行更改。你應該創建新的可變位圖。像這樣:位圖bm = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888); – AterLux
通過創建一個新的位圖變量解決,謝謝你的幫助@AterLux有一個美好的一天:) –