我正在开发一个Android应用程序。在从画廊拍照后,它将转到下一页。但是当我使用小尺寸的图像时,它可以工作。但是更大的尺寸不起作用。我压缩了位图。但现在仍然存在问题。
Homepage.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
//int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
//String picturePath = cursor.getString(columnIndex);
cursor.close();
}
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
final Bitmap bitmap = BitmapFactory.decodeFile(imgDecodableString);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
// Set the Image in ImageView aimgView.setImageBitmap(bitmap);
Toast.makeText(this, "Picture loaded Successfully", Toast.LENGTH_LONG).show();
nextPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent myintent = new Intent(HomePage.this, Image_Recognition.class);
myintent.putExtra("picture", byteArray);
startActivity(myintent);
}
});
} else {
Toast.makeText(this, "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
Log.e("YOUR_APP_LOG_TAG", "I got an error", e);
}
Picture.java
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
final Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
logcat是“JavaBinder:!!! FAILED BINDER TRANSACTION !!!” 这对我的应用来说非常必要。但我找不到任何解决办法。