我一直在环顾四周,但找不到解决我问题的方法。我正在尝试将 bmp1 传递给第二个活动 Profile。粘贴的代码不起作用,任何有可能建议的人都会很棒。这是我第一部分的代码
Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);
int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
if (heightRatio > 1 && widthRatio > 1)
{
if (heightRatio > widthRatio) {
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
bmpFactoryOptions.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);
Bitmap bmp1 = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);
Bitmap alteredBitmap = Bitmap.createBitmap(bmp1.getWidth(),bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(alteredBitmap);
Paint paint = new Paint();
Matrix matrix = new Matrix();
matrix.setValues(new float[] {
.5f, 0, 0,
0, .5f, 0,
0, 0, 1
});
canvas.drawBitmap(bmp, matrix, paint);
ImageView alteredImageView = (ImageView) this.findViewById(R.id.AlteredImageView);
alteredImageView.setImageBitmap(alteredBitmap);
chosenImageView.setImageBitmap(bmp1);
} catch (FileNotFoundException e) { Log.v("ERROR",e.toString());
}
}
Nex.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Uri imageFileUri = intent.getData();
Intent intent = new Intent(Choose.this, Profile.class);
// your bitmap
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bmp1.compress(Bitmap.CompressFormat.PNG, 50, bs);
intent.putExtra("byteArray", bs.toByteArray());
intent.putExtra("location", textView1.getText().toString());
startActivity(intent);
}
}
);
}
}
public class Profile extends Activity {
ImageView picture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
picture = (ImageView) findViewById(R.id.Picture);
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("bytearray");