开发者

Uploading a bitmap to the server with http protocol

开发者 https://www.devze.com 2023-01-06 15:18 出处:网络
i have a camera Activity after which i take a pictureand saving it to gallery and uploading to the server My uploadcodeis not working, i needhelp on this?

i have a camera Activity after which i take a picture and saving it to gallery and uploading to the server My upload code is not working, i need help on this?

// image capture

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);

//image Saving

if(requestCode==0&&resultCode==RESULT_OK)

{

    Bundle extras = data.getExtras();
    Bitmap b = (Bitmap) extras.get("data");

    ImageView mImg;
    mImg = (ImageView) findViewById(R.id.head);
    mImg.setImageBitmap(b);

    // save 开发者_开发百科image to gallery
    Shot = "HeadShot"; //Long.toString(System.currentTimeMillis());
    MediaStore.Images.Media.insertImage(getContentResolver(), b, Shot, NAME);

}

//Upload to the server

public void Upload(String url, HttpEntity imgdata) throws Exception, Exception {

    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);
    post.setHeader("Content-Type", "bitmap; charset=utf-8");
    post.setURI(new URI(url));
    post.setEntity(imgdata);
    HttpUriRequest request = post;
    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    return entity.getContent();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号