Android: getting very blurred image from capture camera - android

I'm capturing image from camera in horizontal scroll-view .When i select that image and display in full image in Image-view its getting very blurry. Why not display clear image in imageview.How to solve this .Thanks in advance
btnCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
Log.e("Camera", " Open");
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
Bitmap photoBitMap = (Bitmap) data.getExtras().get("data");}
}

Related

Take a picture and name it

I have built an Android application that allows the user to take pictures, I don't need to save the picture to the photo album but I want to give to picture a custom name and I don't know how to do.
This is how I open the camera:
addButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
});
and this is how I save the photo:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if( requestCode == CAMERA_PIC_REQUEST) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
DataManager.bars.get((Integer) getIntent().getSerializableExtra("bar")).images.add(thumbnail); // here I save the picture to my custom object
this.adapter.notifyDataSetChanged(); // I update the recycler view in order to see the pic
} else {
Toast.makeText(this, "Picture Not taken", Toast.LENGTH_LONG).show();
}
}

upload image from gallery on android studio

i am trying to upload image from gallery and display it on image view but i am getting this error
I/System.out: resolveUri failed on bad bitmap uri: content://media/external/images/media/35
my code:
public void btimage(View view)
{
Intent i = new Intent(
Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, 100);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==100 && resultCode==RESULT_OK)
{
Uri uri= data.getData();
imgView.setImageURI(uri);
}
}
try this
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
for
MediaStore.Images.Media.INTERNAL_CONTENT_URI

Android continuous Image capture after saving first image (Intent - ACTION_IMAGE_CAPTURE)

Hi I am developing an app which requires to take pics which has to be sent over email. As the camera intent starts camera starts and it allows me to capture an image, when i press SAVE image is displayed in the image view.
Now i need to continue taking images, i.e., after pressing SAVE the camera should start again and be ready to capture pics till i click back button.
Could anyone please help?
For now my code is
Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(FileColumns.MEDIA_TYPE_IMAGE);
camIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(camIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
{
if (resultCode == RESULT_OK)
{
ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setImageURI(fileUri);
}
else if (resultCode == RESULT_CANCELED)
{
}
}
}
Trigger the same intent again on activity result to start the camera again and handle it here only till when you want to capture the images.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
{
if (resultCode == RESULT_OK)
{
ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setImageURI(fileUri);
Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(FileColumns.MEDIA_TYPE_IMAGE);
camIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(camIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
else if (resultCode == RESULT_CANCELED)
{
}
}
}

Detect if Cam is front or back

I take a picture with android :
bComenzarVisita.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(i, CAMERA_PIC_INI_REQUEST);
}
});
The thing is when the user use front cam, the pic get flipped, and I want to rotate it in this case. Rotating and flipping is no problem.
How can I know in the method : onActivityResult which camera the user has used ( front or back)
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case CAMERA_PIC_INI_REQUEST:
if (resultCode == RESULT_OK) {
// If front camera used, flip pic
}
break;
...
}
}

camera activity does not return to the previous/caller activity

I read an text input from the user, this input i use it as a name of a picture i'm taking by the camera.
i store this name and the path of the image name into Sqlite Database.
what I'm trying to do is, after clicking OK to accept the taken picture, i want the saved path to be displayed in a toast.
the problem is, when I click OK to accept the picture, nothing is being displayed and i cant switch from the camera activity to the activity that called the camera activity"the previous activity"
Note: I'm using the emulator not a real device.
OnClickListener btn_TakePictureListener = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String imgPath = retrievePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri(imgPath));
startActivityForResult(intent, RequestCode);
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RequestCode && resultCode == RESULT_OK) {
String s = data.getData().toString();
Toast.makeText(getBaseContext(), ""+s, Toast.LENGTH_SHORT).show();
}
}
if you are passing Uri for you image then you can retrieve image as taken by camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
Environment.getExternalStorageDirectory(), "temp.jpg")));
startActivityForResult(intent, 1);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
// Set the file save path with directory
File picture = new File(Environment.getExternalStorageDirectory()
+ "/temp.jpg");
Uri imageuri= Uri.fromFile(picture);
//set to imageview here
}
}
EDIT:
For Getting data uri in onActivityResult start Camra Activiyt as:
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,IMAGE_UNSPECIFIED);
startActivityForResult(intent, 2);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
Uri uriimg = data.getData();
Toast.makeText(getBaseContext(), ""+uriimg.toString(), Toast.LENGTH_SHORT).show();
}
}

Categories

Resources