2

我一直在环顾四周,但找不到解决我问题的方法。我正在尝试将 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");
4

3 回答 3

1

采用

intent.putExtra("BitmapImage", bmp1);

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");  
于 2013-10-19T07:34:29.367 回答
0

您的代码中有错误。您正在使用字符串“byteArray”作为放置字节数组的键,但使用不同的字符串键“图像”在配置文件活动中检索

于 2013-10-19T07:31:52.043 回答
0

不用想那么多。在选择活动中取一张静态位图并在配置文件活动中使用它。希望这将帮助您理解:

Choose.java
    static Bitmap bit=null;
  //then assign bitmap when it available
   bit=bmp1 //this is your bitmap

 //now at Profile.java use Choose.bit
   if(Choose.bit!=null)
 {
     profimageview.setBitmap(Choose.bit); 
 }
于 2013-10-19T07:39:58.957 回答