我試圖操縱的圖像的像素,但它給出了一個錯誤:圖像像素進行處理,誤差:java.lang.IllegalArgumentException異常
java.lang.IllegalArgumentException: x must be < bitmap.width()
這是我的代碼..
Uri selectedImg = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImg, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Toast.makeText(this, "Successfull!", Toast.LENGTH_LONG);
image = (ImageView)findViewById(R.id.imageView);
image.setImageBitmap(BitmapFactory.decodeFile(picturePath));
BitmapDrawable abmp = (BitmapDrawable) image.getDrawable();
bmp = abmp.getBitmap();
image.setImageBitmap(bmp);
brightBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
operation = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
for (int i = 0; i < bmp.getWidth(); i++) {
for (int j = 0; j < bmp.getHeight(); i++) {
int p = bmp.getPixel(i, j);
int r = Color.red(p);
int b = Color.blue(p);
int g = Color.green(p);
int alpha = Color.alpha(p);
r = r + 100;
g = g + 100;
b = b = 100;
alpha = alpha + 100;
operation.setPixel(i, j, Color.argb(alpha, r, g, b));
}
}
image.setImageBitmap(operation);
}
});
}
}
這是logcat的錯誤:
04 20:11:11.076 19366-19366/com.example..photoeditingapp E/AndroidRuntime: FATAL EXCEPTION: main
03-04 20:11:11.076 19366-19366/com.example..photoeditingapp E/AndroidRuntime: Process: com.example.zohair.photoeditingapp, PID: 19366
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: java.lang.IllegalArgumentException: x must be < bitmap.width()
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.graphics.Bitmap.checkPixelAccess(Bitmap.java:1449)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.graphics.Bitmap.getPixel(Bitmap.java:1401)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at com.example.zohair.photoeditingapp.MainActivity$3.onClick(MainActivity.java:95)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.view.View.performClick(View.java:4640)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19425)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:146)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5593)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
03-04 20:11:11.076 19366-19366/com.example.zohair.photoeditingapp E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
03-04 20:11:12.676 19366-19366/com.example.zohair.photoeditingapp I/Process: Sending signal. PID: 19366 SIG: 9
添加您在logcat中發生的錯誤。 – RominaV
請爲您的錯誤發佈堆棧跟蹤 –
對不起,我新來的Stackoverflow,所以我可能不會把東西放在他們的位置 –