1

I am taking a picture from android phone camera and placing it on imageview. now I want to take that src of imageview so that I could upload it to server. How can I take src of imageview?

Here is my code

public class CameraActivity extends Activity implements View.OnClickListener {
ImageView iv;
Button bCapture, bSetWall;
Intent i;
int CameraResult = 0;
Bitmap bmp;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initialize();
    InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
    bmp = BitmapFactory.decodeStream(is);
}

private void initialize() {
    iv = (ImageView)findViewById(R.id.ivCamera);
    bCapture = (Button)findViewById(R.id.bCapture);
    bSetWall = (Button)findViewById(R.id.bSetWall);
    bCapture.setOnClickListener(this);
    bSetWall.setOnClickListener(this);
}

public void onClick(View v) {
    switch(v.getId()) {
    case R.id.bCapture:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, CameraResult);
        break;
    case R.id.bSetWall:
        try {
            getApplicationContext().setWallpaper(bmp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        break;
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        iv.setImageBitmap(bmp);
        //String v = iv.getTag().toString();
        //Toast.makeText(getApplicationContext(), v, Toast.LENGTH_LONG).show();
    }
}


}
Om3ga
  • 30,465
  • 43
  • 141
  • 221

2 Answers2

1

convert the bitmap into byte array and send it to the server

Bitmap bmp = intent.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
user1203673
  • 1,015
  • 7
  • 15
  • so after adding these lines in my code then do I have to upload `byteArray`? Secondly I am using php on the server side so how will I deal with this byte array on the server side? – Om3ga Jun 11 '12 at 04:15
  • u can convert byte array into base64 string and send to the server – user1203673 Jun 11 '12 at 04:24
1

It is possible to Upload Image View Without save in sdcard or phone Location store. if you want to save image after take picture from camera then you need to convert image view in bitmap and save it in sdcard. Again you need to convert sdcard image in bitmap to upload it server.

Link1

Link

thanks

Community
  • 1
  • 1
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37