简体   繁体   English

ANDROID STUDIO:使用Camera API拍照->将此图片发送到另一个活动

[英]ANDROID STUDIO: Take picture with Camera API -> Send this picture to another activity

After I take a picture with the Camera API, this picture displays on the screen/this activity. 使用Camera API拍照后,该图片将显示在屏幕/此活动中。 I want to send this picture that covers the whole screen to another activity called PictureEditor. 我想将覆盖整个屏幕的图片发送到另一个名为PictureEditor的活动。 There I will add functionality that can edit the picture. 在那里,我将添加可以编辑图片的功能。

  // Code in MainActivity
  mCamera.takePicture(null, null, mPicture);
  Intent i = new Intent(getApplicationContext(), PictureEditor.class);
  Bitmap b = getBitmapFromView(mPreview);
  ByteArrayOutputStream bs = new ByteArrayOutputStream();
  b.compress(Bitmap.CompressFormat.PNG, 50, bs);
  i.putExtra("byteArray", bs.toByteArray());
  startActivity(i);

In PictureEditor I have this code in OnCreate. 在PictureEditor中,我在OnCreate中有此代码。

  // Code in PictureEditor
  if(getIntent().hasExtra("byteArray")) {
  ImageView previewThumbnail = new ImageView(this);
  Bitmap b = BitmapFactory.decodeByteArray(
               getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);
        previewThumbnail.setImageBitmap(b);
    }

What can I do to retrive this picture in PictureEditor, and that this picture is the only thing that is visible on the screen in this activity? 我该怎么做才能在PictureEditor中检索此图片,并且该图片是此活动在屏幕上唯一可见的东西? (Decode the bitmap and display it as an image on the screen) (将位图解码并在屏幕上显示为图像)

Thanks for all kind of help! 感谢您提供的所有帮助!

// Code in PictureEditor
  if(getIntent().hasExtra("byteArray")) {
  ImageView previewThumbnail = new ImageView(this);
  Bitmap b =(Bitmap) getIntent().getParcelableExtra("byteArray");
        previewThumbnail.setImageBitmap(b);
    }

But if you send information between activitys. 但是,如果您在活动之间发送信息。 The size of this information cant exceed 1 MB. 此信息的大小不能超过1 MB。 You have to compress your bitmap. 您必须压缩位图。

代替startActivity请调用startActivityForResult并在同一活动的onActivityResult回调方法中从捆绑包中获取图像,并将图像传递给新的Activity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM