代码之家  ›  专栏  ›  技术社区  ›  Vishal Sharma

以位图形式发送图像(通过意向或共享参考)

  •  -1
  • Vishal Sharma  · 技术社区  · 8 年前

    发件人活动:

    camera=(ImageButton)findViewById(R.id.camera);
                gallery=(ImageButton)findViewById(R.id.gallery);
          camera.setOnClickListener(new View.OnClickListener() {
    
              @Override
              public void onClick(View view) {
                  Intent i =new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
                  startActivityForResult(i, 50);
              }
          });
    
        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent pickPhoto = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(pickPhoto , 40);
            }
        });
    }
    

    package com.androidlink.navigation_bottom;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.support.v7.app.AppCompatActivity;
    
    
    import android.os.Bundle;
    import android.widget.ImageView;
    public class Image_set_Activity extends AppCompatActivity 
    {
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_set_);
        ImageView IV = (ImageView) findViewById(R.id.simpleImageView);
    
      }
    }
    
    2 回复  |  直到 8 年前
        1
  •  -1
  •   Kevin Kurien    8 年前

    在里面 onActivityResult

    Bitmap photo = (Bitmap) data.getExtras().get("data");
                Log.d("===uploadPhoto","camera : "+photo);
                *//* Passing BITMAP to the Second Activity *//*
                Intent intentCamera = new Intent(this, SecondAvtivity.class);
                IntentCamera.putExtra("BitmapImage", photo);
                startActivity(intentCamera);  
    

    Bitmap fromCamera = getIntent().getParcelableExtra("BitmapImage");
            imageView.setImageBitmap(fromCamera)
    
        2
  •  -1
  •   suresh madaparthi    8 年前

    尝试使用此代码

    第一节课

     ImageView img=findViewById(R.id.imgId);
     BitmapDrawable bmd= (BitmapDrawable) img.getDrawable();
     Bitmap bt= bmd.getBitmap();
     final byte[] imgarry = bt.getNinePatchChunk();
    
      Intent intent = new Intent (FirstClass.this,SecondClass.class);
      Intent.putExtra(“imgs”,imgarry);
      startActivity(intent);
    

    二等舱

     Intent in = getIntent();
     byte[] ary= in.getByteArrayExtra(“imgs”);
     Bitmap bm= BitmapFactory.decodeByteArray(ary,0,ary.length);
     imageView.setImageBitmap(bm);