I have an app from which i have to capture an image from camera activity and using content resolver i have insert that image to media.EXTERNAL_CONTENT_URI and i have getString() the path of that image and passed it to bundle in other activity.
from there,I have get that path and put it in Bitmap bitmap = BitmapFactory.decodeFile(filepath);
but it's showing FILENOTFOUNDEXCEPTION and NULLPOINTEREXCEPTION.How to resolve that?
so I am also trying another approach such that the image i got in first activity should first be set to a file and then i decode that file easily?
please suggest me the way to do that.
UPDATES-->
CODE: `//pass image path to other activity`
case PICK_FROM_CAMERA : if (resultCode == RESULT_OK)
{
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE,"image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
filepath = uri.getPath();
Bitmap photo = (Bitmap) data.getExtras().get("data");
//((ImageView)findViewById(R.id.selectedimage)).setImageBitmap(photo);
OutputStream outstream;
try
{
outstream = getContentResolver().openOutputStream(uri);
photo.compress(Bitmap.CompressFormat.JPEG,100,outstream);
outstream.close();
}
catch (FileNotFoundException e) {}
catch (IOException e) {}
Intent intent = new Intent(this.getApplicationContext(),AnimationActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("flag", 0);
bundle.putString("filepath", filepath);
intent.putExtras(bundle);
startActivity(intent);
}
Code: //show that image
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img = (ImageView)findViewById(R.id.background);
Bitmap border = BitmapFactory.decodeResource(getResources(),R.drawable.border1);
Bundle extra = getIntent().getExtras();
mfilepath = extra.getString("filepath");
int flag = extra.getInt("flag");
if(flag==1)
{
bgr= BitmapFactory.decodeFile(mfilepath);
}
if(flag==0)
{
bgr=BitmapFactory.decodeFile(mfilepath);
OutputStream outstream;
try
{
outstream = getContentResolver().openOutputStream(Uri.fromFile(new File(mfilepath)));
//bgr.compress(Bitmap.CompressFormat.JPEG,100,outstream);
outstream.close();
}
catch (FileNotFoundException e) {}
catch (IOException e) {}
}
bmOverlay = Bitmap.createBitmap(border.getWidth(),border.getHeight(),bgr.getConfig());
canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmOverlay, 0, 0, null);
canvas.drawBitmap(bgr, 0, 0, null);
canvas.drawBitmap(border,0,0, null);
canvas.save();
img.setImageBitmap(bmOverlay);
Try this simple method, I think it should solve your problem.
private void savePicture(String filename, Bitmap b, Context ctx) {
try {
FileOutputStream out;
out = ctx.openFileOutput(filename, Context.MODE_WORLD_READABLE);
b.compress(Bitmap.CompressFormat.JPEG, 40, out);
if (b.compress(Bitmap.CompressFormat.JPEG, 40, out) == true)
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Edit 1: Although I am not sure exactly what you are asking, I think you might be looking for this method:
private void takePicture() {
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, 0);
}
Use of FileOutputStream instead of OutputStream solved ma problem.
case PICK_FROM_CAMERA : if (resultCode == RESULT_OK)
{
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE,"image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
filepath = uri.getPath();
Bitmap photo = (Bitmap) data.getExtras().get("data");
try
{
FileOutputStream outstream; =new FileOutputStream(filepath);
photo.compress(Bitmap.CompressFormat.JPEG,100,outstream);
outstream.close();
}
catch (FileNotFoundException e) {}
catch (IOException e) {}
Intent intent = new Intent(this.getApplicationContext(),AnimationActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("flag", 0);
bundle.putString("filepath", filepath);
intent.putExtras(bundle);
startActivity(intent);
}
Code: //show that image
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img = (ImageView)findViewById(R.id.background);
Bitmap border = BitmapFactory.decodeResource(getResources(),R.drawable.border1);
Bundle extra = getIntent().getExtras();
mfilepath = extra.getString("filepath");
bgr= BitmapFactory.decodeFile(mfilepath);
bmOverlay = Bitmap.createBitmap(border.getWidth(),border.getHeight(),bgr.getConfig());
canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmOverlay, 0, 0, null);
canvas.drawBitmap(bgr, 0, 0, null);
canvas.drawBitmap(border,0,0, null);
canvas.save();
img.setImageBitmap(bmOverlay);
Related
In the code below, you can see that I have created an imageview using a bitmap. What I want to know is how I can save an image of that imageview to my camera roll. Thanks!
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.key_code_zoom);
title = (TextView) findViewById(R.id.accountTitleLarge);
imageView = (ImageView) findViewById(R.id.keyCodeLarge);
Intent callingActivity = getIntent();
Bundle callingBundle = callingActivity.getExtras();
if (callingBundle != null) {
String titleText = callingBundle.getString("title");
byte[] bytes = getIntent().getByteArrayExtra("bitmapbytes");
bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
title.setText(titleText);
imageView.setImageBitmap(bmp);
}
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
supportFinishAfterTransition();
}
});
}
To save an image in gallery, you must first get the bitmap and then save it.
private void imageToRoll(){
imageView.buildDrawingCache();
Bitmap image = imageView.getDrawingCache(); // Gets the Bitmap
MediaStore.Images.Media.insertImage(getContentResolver(), imageBitmap, imagTitle , imageDescription); // Saves the image.
}
Also, set the permission in your manifest.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
If you are looking for some code that will help you save the Image from the ImageView to your phone storage then the following code will help you
public String getImageFromView() {
imageview.setDrawingCacheEnabled(true);
// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
imageview.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
imageview.layout(0, 0, imageview.getMeasuredWidth(), imageview.getMeasuredHeight());
imageview.buildDrawingCache(true);
//Define a bitmap with the same size as the view
Bitmap b = imageview.getDrawingCache();
String imgPath = getImageFilename();
File file = new File(imgPath);
try {
OutputStream os = new FileOutputStream(file);
b.compress(Bitmap.CompressFormat.JPEG, 90, os);
os.flush();
os.close();
ContentValues image = new ContentValues();
image.put(Images.Media.TITLE, "NST");
image.put(Images.Media.DISPLAY_NAME, imgPath.substring(imgPath.lastIndexOf('/')+1));
image.put(Images.Media.DESCRIPTION, "App Image");
image.put(Images.Media.DATE_ADDED, System.currentTimeMillis());
image.put(Images.Media.MIME_TYPE, "image/jpg");
image.put(Images.Media.ORIENTATION, 0);
File parent = file.getParentFile();
image.put(Images.ImageColumns.BUCKET_ID, parent.toString()
.toLowerCase().hashCode());
image.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, parent.getName()
.toLowerCase());
image.put(Images.Media.SIZE, file.length());
image.put(Images.Media.DATA, file.getAbsolutePath());
Uri result = mContext.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, image);
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return imgPath;
}
you will have to provide a file path getImageFilename();this function provides the path where the file is suppose to be stored. The ContentValues will be responsible to let the images be scanned in gallery.
Hope this helps.
Here i am making drawable view into bitmap.
mDrawingPad.setVisibility(View.VISIBLE);
BitmapDrawable ob = new BitmapDrawable(getResources(),
bitmapconv);
DrawingView mDrawingView=new
DrawingView(Previewimage.this);
mDrawingPad.addView(mDrawingView);
mDrawingView.setBackground(ob);
mDrawingView.buildDrawingCache();
drawbitmap=mDrawingView.getDrawingCache();
I need to convert this into URI to send to image cropper library
CropImage.activity(uri).start(Previewimage.this);
/*This saveImage method will return String path*/
path = saveImage();
Uri uri = Uri.parse(path);
/****************************************************/
private String saveImage()
{
Bitmap bitmap;
mDrawingView.setDrawingCacheEnabled(true);
mDrawingView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
mDrawingView.buildDrawingCache();
bitmap = Bitmap.createBitmap(mDrawingView.getDrawingCache());
String state = Environment.getExternalStorageState();
String root = "";
String fileName = "/MyImage" + System.currentTimeMillis() + "Image"+ ".jpg";
String parent = "App_Name";
File mFile;
if (Environment.MEDIA_MOUNTED.equals(state)) {
root = Environment.getExternalStorageDirectory().toString();
mFile = new File(root, parent);
if (!mFile.isDirectory())
mFile.mkdirs();
} else {
root = FriendsImageSending.this.getFilesDir().toString();
mFile = new File(root, parent);
if (!mFile.isDirectory())
mFile.mkdirs();
}
String strCaptured_FileName = root + "/App_Name" + fileName;
File f = new File(strCaptured_FileName);
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 95, bytes);
FileOutputStream fo;
fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
bitmap.recycle();
System.gc();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return strCaptured_FileName;
}
This part of code works:
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
your_bitmap_image.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(your_context.getContentResolver(), your_bitmap_image, "your_title", null);
Uri uri = Uri.parse(path);
just try to replace the areas that I mentioned in it
in the place of "your_context" if you are in an activity put this:
MediaStore.Images.Media.insertImage(getContentResolver(), your_bitmap_image, "your_title", null);
Uri uri = Uri.parse(path);
if you are in a fragment :
MediaStore.Images.Media.insertImage(getContext().getContentResolver(), your_bitmap_image, "your_title", null);
Uri uri = Uri.parse(path);
Use this method:
public Uri getImageUri(Context ctx, Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(ctx.getContentResolver(),
bitmap, "Temp", null);
return Uri.parse(path);
}
If you are calling this method inside an Activity then call this method like this:
getImageUri(YourClassName.this, yourbitmap);
But if you are calling this in an Fragment then call like this:
getImageUri(getActivity(), yourbitmap);
I crated one image store in sd card to save that image and then i need that image path and name of the image pls tell how to get the name and path of the image
public void saveBitmap(Bitmap bmp)
{
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/NewFolder";
File dir = new File(file_path);
if(!dir.exists())
dir.mkdirs();
File file = new File(dir, "myImage.png");
FileOutputStream fOut;
try {
fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
String name = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/NewFolder";
storedimagepath=name.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
i got this
void getImageCAMERandGALLERY()
{
final String [] items = new String[] { "Take from Camera" , "Select from Gallery" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this , android.R.layout.select_dialog_item , items);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Image");
builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
private Uri mImageCaptureUri;
#Override
public void onClick(DialogInterface dialog , int item)
{
if (item == 0)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory() , "tmp_avatar_"
+ String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT , mImageCaptureUri);
try
{
intent.putExtra("return-data" , true);
startActivityForResult(intent , PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e)
{
e.printStackTrace();
}
} else
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent , "Complete action using") , PICK_FROM_FILE);
}
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
#Override
protected void onActivityResult(int requestCode , int resultCode , Intent data)
{
if (resultCode != RESULT_OK)
return;
switch (requestCode) {
case PICK_FROM_CAMERA:
break;
case PICK_FROM_FILE:
mImageCaptureUri = data.getData();
break;
case CROP_FROM_CAMERA:
Bundle extras = data.getExtras();
if (extras != null)
{
Bitmap photo = extras.getParcelable("data");
UserImage.setImageBitmap(photo);
try
{
Uri tempUri = getImageUri(getApplicationContext() , photo);
storeUriInFile(tempUri);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
}
public Uri getImageUri(Context inContext , Bitmap inImage)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG , 100 , bytes);
String path = Images.Media.insertImage(inContext.getContentResolver() , inImage , "Title" , null);
return Uri.parse(path);
}
void storeUriInFile(Uri uri)
{
try
{
Bitmap my_btmp = Media.getBitmap(this.getContentResolver() , uri); // BitmapFactory.decodeStream(BufferedInputStream);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
my_btmp.compress(CompressFormat.PNG , 0 , bos);
byte [] bitmapdata = bos.toByteArray();
long timeinmilliseconds = new Date().getTime();
// store byte array in a image file
String filepath = Environment.getExternalStorageDirectory().getPath();
File file = new File(filepath , SpeakerBox_FOLDER);
if (!file.exists())
file.mkdirs();
String mFileName = file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".png";
OutputStream out = new FileOutputStream(mFileName);
out.write(bitmapdata);
out.flush();
out.close();
String filename = mFileName;
storedimagepath = filename;
} catch (Exception e)
{
}
}
you can try like that
String name = Environment.getExternalStorageDirectory().getAbsolutePath() + "/NewFolder";
storedimagepath=name.toString();
File f = new File(storedimagepath+"/photo.jpg");
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
ImageView mImgView1 = (ImageView)findViewById(R.id.imageView);
mImgView1.setImageBitmap(bmp);
I captured an image of 2592x1936 from mobile's camera, converted it into bitmap. I displayed it my imageview asmyImageVew.setImageBitmap(myBitmap);
after displaying this bitmap i perform some manipulation over this image(inside the imageview), now i m saving this using
Bitmap bitmap;
// frmCaptureThis is the root framelayout (this contains my imageview)
View v1 = frmCaptureThis;
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
saveImgToSDcard(bitmap);
this is saving my image to SD card but not with the 2592x1936 resolutions, its saving my image with size equal to the imageView size (i.e 400X620). i want to save the image with original resolution i.e 2592x1936
EDIT
here is my code for taking image via intent
// ////////// Capture Button Handler//////////////////
btnCapture.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION,
"From your Camera");
imageUri = getActivity().getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, REQUEST_OPEN_CAMERA);
}
});
and Here is my on Activity Result method
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String imageurl = null;
if (requestCode == REQUEST_OPEN_CAMERA
&& resultCode == Activity.RESULT_OK) {
captureFlage = true;
relTapToCapture.setEnabled(false);
relHeader.setVisibility(View.INVISIBLE);
frmCaptureThis.setVisibility(View.VISIBLE);
btnCapture.setVisibility(View.VISIBLE);
btnSave.setVisibility(View.VISIBLE);
txtTapToCapture.setVisibility(View.INVISIBLE);
try {
thumbnail = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), imageUri);
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
imageurl = getRealPathFromURI(imageUri);
if (thumbnail.getWidth() > thumbnail.getHeight()) {
// Log.i("Orientation", "LandScape");
// thumbnail = rotateImage_90(thumbnail);
imgCaptured.setImageBitmap(thumbnail);
} else {
// Log.i("Orientation", "Portrait");
imgCaptured.setImageBitmap(thumbnail);
}
File file = new File(imageurl);
boolean deleted = file.delete();
}
super.onActivityResult(requestCode, resultCode, data);
}
and here is my method for saving the image in SD card
public void saveImgToSDcard(Bitmap bitmap) {
Calendar cal = Calendar.getInstance();
System.out.println("Current milliseconds since 13 Oct, 2008 are :"
+ cal.getTimeInMillis());
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "brandYourImage" + cal.getTimeInMillis()
+ ".jpg");
try {
f.createNewFile();
} catch (IOException e) {
}
// write the bytes in file
FileOutputStream fo = null;
try {
fo = new FileOutputStream(f);
} catch (FileNotFoundException e) {
}
try {
fo.write(bytes.toByteArray());
} catch (IOException e) {
}
// remember close de FileOutput
try {
fo.close();
Toast.makeText(getActivity(), "Saved Successfully",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
}
}
I know this question has been asked so many times in this forum. But still I couldn't get the solution.
Basically in my application, I am calling an inbuilt camera intent, capturing image and displaying a bitmap in imageview and storing it in sd card. Now the image what i get in my folder is of small size like a thumbnail.
My code is
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(Intent.createChooser(cameraIntent, "Select picture"), CAMERA_REQUEST);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
if (photo != null) {
imageView.setImageBitmap(photo);
}
// Image name
final ContentResolver cr = getContentResolver();
final String[] p1 = new String[] { MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATE_TAKEN };
Cursor c1 = cr.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null,
null, p1[1] + " DESC");
if (c1.moveToFirst()) {
String uristringpic = "content://media/external/images/media/" + c1.getInt(0);
Uri newuri = Uri.parse(uristringpic);
String snapName = getRealPathFromURI(newuri);
Uri u = Uri.parse(snapName);
File f = new File("" + u);
String fileName = f.getName();
editTextPhoto.setText(fileName);
checkSelectedItem = true;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
byte[] bitmapdata = bos.toByteArray();
// Storing Image in new folder
StoreByteImage(mContext, bitmapdata, 100, fileName);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
// Delete the image from the Gallery
getContentResolver().delete(newuri, null, null);
}
c1.close();
}
} catch (NullPointerException e) {
System.out.println("Error in creating Image." + e);
} catch (Exception e) {
System.out.println("Error in creating Image." + e);
}
System.out.println("*** End of onActivityResult() ***");
}
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public boolean StoreByteImage(Context pContext, byte[] pImageData,
int pQuality, String pExpName) {
String nameFile = pExpName;
// File mediaFile = null;
File sdImageMainDirectory = new File(
Environment.getExternalStorageDirectory() + "/pix/images");
FileOutputStream fileOutputStream = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 0;
Bitmap myImage = BitmapFactory.decodeByteArray(pImageData, 0,
pImageData.length, options);
if (!sdImageMainDirectory.exists()) {
sdImageMainDirectory.mkdirs();
}
sdImageMainDirectory = new File(sdImageMainDirectory, nameFile);
sdImageMainDirectory.createNewFile();
fileOutputStream = new FileOutputStream(
sdImageMainDirectory.toString());
BufferedOutputStream bos = new BufferedOutputStream(
fileOutputStream);
myImage.compress(CompressFormat.JPEG, pQuality, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
Toast.makeText(pContext, e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(pContext, e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
and ImageView in main.xml is
<ImageView
android:id="#+id/test_image"
android:src="#drawable/gray_pic"
android:layout_width="180dp"
android:layout_height="140dp"
android:layout_below="#id/edit2"
android:layout_toRightOf="#id/edit3"
android:layout_alignParentRight="true"
android:layout_marginTop="7dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
/>
With this code i get an Imageview and the image stores in my folder with small size.
If I add intent.putExtra then neither image captured displays in ImageView nor image creates in new folder.
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
path += "/myFolder/myPicture.jpg";
File file = new File(path);
Uri outputFileUri = Uri.fromFile(file);
cameraIntent.putExtra("output", outputFileUri);
startActivityForResult(Intent.createChooser(cameraIntent, "Select Picture"), CAMERA_REQUEST);
}
Don't know where I am struck..
Any help on this would be appreciated.
Use Camera intent as:
Intent photoPickerIntent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempFile());
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
photoPickerIntent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(photoPickerIntent,"Select Picture"),TAKE_PICTURE);
//getTempFile()
private Uri getTempFile() {
// if (isSDCARDMounted()) {
File root = new File(Environment.getExternalStorageDirectory(), "My Equip");
if (!root.exists()) {
root.mkdirs();
}
Log.d("filename",filename);
File file = new File(root,filename+".jpeg" );
muri = Uri.fromFile(file);
photopath=muri.getPath();
Item1.photopaths=muri.getPath();
Log.e("getpath",muri.getPath());
return muri;
// } else {
// return null;
}
//}
private boolean isSDCARDMounted(){
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED))
return true;
else
return false;
}
And Check in your Folder, click on thumbnail it will show actual image