按钮

2011-11-24 24 views
-2

点击时拍照我有一个像this--
要求在我的项目上的图像按钮,点击后,相机要打开并拍摄照片,并且拍摄的照片应显示在TextViewimageView按钮

+2

-1你是令人难以置信的人!你首先要求打开相机..然后在imageview上显示相机...现在在你的评论要求发送图像到服务器,我想接下来你会问比较..然后添加效果..和所有这些直接代码?男人你不认为你应该尝试和网上搜索的东西..是的,如果你不能让一个开发者 – MKJParekh

+0

弗兰克:即时通讯同意。社区应该阻止这样的人来到这里 – Sameer

+0

去从freelancer.com一些廉价的程序员 – Sam

回答

2

布局

<ImageView onClik=takePhoto /> 

代码

public void takePhoto(View view) { 
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 
    File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg"); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, 
      Uri.fromFile(photo)); 
    imageUri = Uri.fromFile(photo); 
    startActivityForResult(intent, TAKE_PICTURE); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch (requestCode) { 
    case TAKE_PICTURE: 
     if (resultCode == Activity.RESULT_OK) { 
      Uri selectedImage = imageUri; 
      getContentResolver().notifyChange(selectedImage, null); 
      ImageView imageView = (ImageView) findViewById(R.id.ImageView); 
      ContentResolver cr = getContentResolver(); 
      Bitmap bitmap; 
      try { 
       bitmap = android.provider.MediaStore.Images.Media 
       .getBitmap(cr, selectedImage); 

       imageView.setImageBitmap(bitmap); 
       Toast.makeText(this, selectedImage.toString(), 
         Toast.LENGTH_LONG).show(); 
      } catch (Exception e) { 
       Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT) 
         .show(); 
       Log.e("Camera", e.toString()); 
      } 
     } 
    } 
} 

编辑ing: 用于在服务器上上传此图像创建一个HttpConnection并发送服务器上的Iamge的byteStream。例子是here

+0

谢谢:-)你可以告诉我喜欢拍摄的照片应该发送到服务器的二进制格式..如何发送拍摄的图片到服务器的二进制格式? – Victor

+0

Kishore,他做了你的问题,它给了你一个解决方案。现在接受它作为答案。它会帮助你和社区 – Sameer

+0

检查修改后的代码,并接受它是否是正确的答案。 –