Saving a picture into memory - android

I need to use the device camera to take a picture, save it into its memory and get the uri so I can email it afterwards.
I'm using Android 3.2 on a device with no memory card (just 11 gigs of internal storage).
private void takePicture(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == CAMERA_PIC_REQUEST && resultCode == Activity.RESULT_OK){
picture = (Bitmap) data.getExtras().get("data");
pictureView.setImageBitmap(picture);
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "Picture");
values.put(Images.Media.BUCKET_ID, "picture_ID");
values.put(Images.Media.DESCRIPTION, "");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
pictureUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
OutputStream outstream;
try{
outstream = getContentResolver().openOutputStream(pictureUri);
picture.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
outstream.close();
}catch(FileNotFoundException e){
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Any help from someone more experienced with this would be greatly appreciated.

To keep something in memory you'd just declare a variable or data structure to hold it; in this case some form of a byte array seems promising. I don't think that would work very well in this case, though. The heap in Android is usually capped at 16 or 25 mb, and depending on what else your app is doing storing photos would get to an "Out of Memory" exception quickly.
So with no SD card, this leaves you with writing to internal storage. I don't know which, if any, directories on internal storage the app can write without root access and/or mounting the system read/write, but I think the best bet is /data/tmp. See if you can save the pic there. If not, mounting the system read/write isn't so bad either.

Related

how to get photo absolute path from removable SD card

background information
I have been writing a backup photos service, which needs to get all photo absolute paths from Android external storage (like photos stored in 'DCIM' directory and its subdirectores) and upload them to remote server. The problem is how to get all validate photo absolute paths from Android device. Since there is a vast majority of Android devices, it`s tough to ensure the get-photo-absolute-path algorithm to successfully reach all validate photos Gallery directory and traverse all photos paths inside of it.
Now my app only supports uploading photos from primary external storage (not the secondary external storage, like removable SD card). That`s to say.
if the device only has one emulated external storage (on-board flash), camera upload service can scan photo paths on it correctly.
if the device only has a removable storage (like SD card), camera upload service can scan photo paths correctly as well.
the algorithm above scans photo paths from primary external storage which works correctly. But when it comes to
if the device both has a emulated external storage and a removable storage, camera upload service only scans photo paths on the emulated external storage (primary storage), but a majority of users save their photos to the 16G or bigger size removable SD card (secondary storage) which will be ignored by my app, that`s the problem. see the complete issue here.
Code implementation
To get absolute photo path from internal storage, I hard coded an "external directory list",
String[] paths = {
"/DCIM",
"/DCIM/Camera",
"/DCIM/100MEDIA",
// Many Samsung phones mount the external sd card to /sdcard/external_sd
"/external_sd/DCIM",
"/external_sd/DCIM/Camera",
"/external_sd/DCIM/100MEDIA"
};
and combined the absolute path like
String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + path;
I know that`s not the best practice, that`s why ask for help. BTW, see the complete external directory list
Question
To get absolute photo paths from Android storage
check if external storage mounted, then scan photos from internal storage by default. This can fit a majority of getting photo path requirements, see the complete implementation here
let user choose a specific directory to upload photos from SD card (if mounted one)
So I wonder if the proposal above is right or not?
Any comments or reference will be greatly appreciated.
EDIT
Different manufacturers set their SD card mounted point differently, there is no regular rules for that, it almost impossible (or say, bad practice) to scan and upload photos by the app in the background automatically. To get photos path from SD card, the practical way I think is to only scan root directories, then shows such directories in a file browser window to let user choose a specific gallery directory and persist the path locally instead of scanning by the app itself. Because it`s error prone to scan photos directives automatically on SD card.
You can try this way
for popup
private void selectImage()
{
final CharSequence[] items = { "Camera", "Gallery","Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(Detail_mul.this);
builder.setTitle("Add Photo!");
builder.setItems(items, new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int item)
{
if (items[item].equals("Camera"))
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, REQUEST_CAMERA);
} else if (items[item].equals("Gallery")) {
Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select File"),SELECT_FILE);
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
for getting the result
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bm = null;
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CAMERA) {
File f = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : f.listFiles()) {
if (temp.getName().equals("temp.jpg")) {
f = temp;
break;
}
}
try {
BitmapFactory.Options btmapOptions = new BitmapFactory.Options();
bm = BitmapFactory.decodeFile(f.getAbsolutePath(),btmapOptions);
bm = Bitmap.createScaledBitmap(bm, 300, 200, true);
String path = android.os.Environment.getExternalStorageDirectory()+ File.separator+ "Phoenix" + File.separator + "default";
PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit().putString("endum_image_"+count, f.toString()).commit();
OutputStream fOut = null;
File file = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
try {
fOut = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (requestCode == SELECT_FILE)
{
Uri selectedImageUri = data.getData();
//getRealPathFromURI(selectedImageUri);
String tempPath = getPath(selectedImageUri, Detail_mul.this);
PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit().putString("endum_image_"+count, tempPath).commit();
BitmapFactory.Options btmapOptions = new BitmapFactory.Options();
bm = BitmapFactory.decodeFile(tempPath,btmapOptions);
bm = Bitmap.createScaledBitmap(bm, 300, 200, true);
bm = BitmapFactory.decodeFile(tempPath, btmapOptions);
}
} }
I think you are uploading images for your photo service.You can access the gallery to select a particular picture because every picture in your phone is there in your Gallery whether on SDcard or Primary memory.
Code for accessing gallery
you can see
this code.I think this would help

android trouble with saving pictures to internal memory

I'm writing an app for school, of which one of the biggest parts is taking pictures. I came to conclusion that it would be perfect if I could just save them on Internal Storage, so they would be automatically removed during uninstall process.
I ran across few code samples, proving me there is no easy way to do that (and I realized saving images on external memory is a piece of cake too). However, I managed to find that question: Trouble writing internal memory android and came up with something similiar. After some time testing I ran across "Unable to resume activity" exception, but fortunately I've found a tweak: image from camera intent issue in android
Now my code looks like this:
private void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), FITPAL_TEMP_PICTURE_NAME);
Uri outputFileUri = Uri.fromFile(file);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(takePictureIntent, actionCode);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case ACTION_TAKE_PHOTO_B: {
if (resultCode == RESULT_OK) {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), FITPAL_TEMP_PICTURE_NAME);
Bitmap picture = BitmapFactory.decodeFile(file.getAbsolutePath());
if (picture == null) {
showShortToast(R.string.problem_with_taking_a_picture);
return;
}
File dir = getDir(Environment.DIRECTORY_PICTURES, Context.MODE_PRIVATE);
File internalFile = null;
internalFile = new File(dir, generateUniqueFilename());
internalFile.setReadable(true);
internalFile.setWritable(true);
internalFile.setExecutable(true);
try {
internalFile.createNewFile();
FileOutputStream fos = new FileOutputStream(internalFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
picture.compress(Bitmap.CompressFormat.JPEG, JPEG_FILE_QUALITY, bos);
bos.flush();
bos.close();
String filePath = internalFile.getAbsolutePath();
pictureFilePaths.add(filePath);
addPictureThumbnail(filePath);
Log.d("mounted?", "" + Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED));
Log.d("delete test 23123123", "" + file.getAbsolutePath() + " " + file.delete());
} catch (Exception e) {
Log.e("eks", e.getMessage());
showShortToast(R.string.problem_with_taking_a_picture);
}
}
else if (resultCode == RESULT_CANCELED) {
showShortToast(R.string.taking_picture_has_been_cancelled);
}
break;
}
default:
break;
}
}
Basically what I'm trying to do is write a picture to External Storage and move it to Internal Storage. It works in 80% of cases, it's not 100% because it sometimes just "resets" the activity - the new empty layout shows up, just as if it was just created. I have no idea what is happening. I realized that both onSaveInstanceState and onRestoreInstanceState fire in that case and I've no idea why (no exceptions are thrown along the way).
The activity that is invoking all that code is extending FragmentActivity. I've read there are some bugs that might cause that in older versions of Android Support Package, but I've just updated it to version 13 and the problem still persists.
The other thing is that the file saved on external storage won't delete - file.delete() always returns false. Is it a matter of me not having an sdcard? (I mean I have a slot in my phone, but I just have Internal Storage of 16GB). The file gets saved to /mnt/sdcard/Pictures/ folder as if it was emulated somehow.
In advance to the questions: I have both android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE permissions set:
I tried replacing Environment.getExternalStoragePublicDirectory with getCacheDir, getExternalCacheDir and none of them worked either..
I'm testing all that stuff on my Samsung Galaxy SII with Android 4.0.4 (stock)

Capture full resolution image from camera in a secure way (without storing to disk, if possible)

I am developing an app that will allow users to capture images of secure documents and upload those images to a server (a good example of what I'm trying to do is a banking app that allows users to take pictures of checks.)
For security reasons, I do not want the image physically stored on disk at any point, if possible.
When I try to do this with the MediaStore.ACTION_IMAGE_CAPTURE intent, it works... but the resolution is very low. I assume this is to prevent overuse of RAM. I've looked around for solutions, but all of the ones I found involve storing the image on the SD card or internal NAND storage. I do not want to do that.
If it is not possible to avoid storing the photo, is there a way for the image to be stored to a location only accessible to my app? I would then delete the file after it's uploaded. And if I have to do it this way, is there any way to encrypt the photo as it's being stored?
Here's a simplification of my current code, in case that helps at all:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,requestCode);
and
protected void onActivityResult(int requestCode, int resultcode, Intent data)
{
if (resultcode == RESULT_OK)
{
Bitmap bmp = getBitmapFromIntent(data);
}
}
private Bitmap getBitmapFromIntent(Intent intent)
{
Bundle extras = intent.getExtras();
return (Bitmap) extras.get("data");
}
You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstall your application, these files are removed.
String file_path = "/data/data/com.packagename/cache/";
File dir = new File(file_path);
if (!dir.exists())
dir.mkdirs();
File file = new File(dir, "1" + ".jpg");
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write(data); // data in byte format
fos.close();
} catch (FileNotFoundException e) {
Log.e("Not Found", "File not found: " + e.getMessage());
} catch (IOException e) {
Log.e("Not Found", "Error accessing file: " + e.getMessage());
}

Trouble writing internal memory android

void launchImageCapture(Activity context) {
Uri imageFileUri = context.getContentResolver()
.insert(Media.INTERNAL_CONTENT_URI, new ContentValues());
m_queue.add(imageFileUri);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
context.startActivityForResult(i, ImportActivity.CAMERA_REQUEST);
}
The above code, which has always worked, is now generating this exception for me at insert().
java.lang.UnsupportedOperationException: Writing to internal storage is not supported.
at com.android.providers.media.MediaProvider.generateFileName(MediaProvider.java:2336)
at com.android.providers.media.MediaProvider.ensureFile(MediaProvider.java:1851)
at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:2006)
at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1974)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:150)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:140)
at android.os.Binder.execTransact(Binder.java:287)
at dalvik.system.NativeStart.run(Native Method)
It is not a space issue, and the only thing I changed was the package of an unrelated class all together. Also, I restarted my phone.
Facing same problem here, I was happy to find this thread. Even though two things were bugging me in this workaround, this post had me looking in the right direction. I'd like to share my own workaround/solution.
Let me begin by stating what I did not see myself living with.
First, I did not want to leave the application private file as MODE_WORLD_WRITEABLE. This looks like non-sense to me, although I cannot figure exactly how another application could access this file unless knowing where to look for it with complete name and path. I'm not saying it is necessarily bad for your scenario, but it is still bugging me somehow. I would prefer to cover all my bases by having picture files really private to my app. In my business case, pictures are of no use outside of the application and by no means should they be deleteable via, say, the Android Gallery. My app will trigger cleanup at an appropriate time so as to not vampirize Droid device storage space.
Second, openFileOutput() do not leave any option but to save the resulting file in the root of getFilesDir(). What if I need some directory structure to keep things in order? In addition, my application must handle more than one picture, so I would like to have the filename generated so I can refer to it later on.
See, it is easy to capture a photo with the camera and save it to public image area (via MediaStore) on the Droid device. It is also easy to manipulate (query, update, delete) media from MediaStore. Interestingly, inserting camera picture to MediaStore genreates a filename which appears to be unique. It is also easy to create private File for an application with a directory structure. The crux of the "Capturea camera picture and save it to internal memory" problem is that you can't do so directly because Android prevents ContentResolver to use Media.INTERNAL_CONTENT_URI, and because private app files are by definition not accessible via the (outside) Camera activity.
Finally I adopted the following strategy:
Start the Camera activity for result from my app with the Intent to capture image.
When returning to my app, insert capture to the MediaStore.
Query the MediaStore to obtain generated image file name.
Create a truly internal file onto whatever path relative to private application data folder using Context.getDir().
Use an OutputStream to write Bitmap data to this private file.
Delete capture from MediaStore.
(Optional) show an ImageView of the capture in my app.
Here is the code starting the cam:
public void onClick (View v)
{
ContentValues values = new ContentValues ();
values.put (Media.IS_PRIVATE, 1);
values.put (Media.TITLE, "Xenios Mobile Private Image");
values.put (Media.DESCRIPTION, "Classification Picture taken via Xenios Mobile.");
Uri picUri = getActivity ().getContentResolver ().insert (Media.EXTERNAL_CONTENT_URI, values);
//Keep a reference in app for now, we might need it later.
((XeniosMob) getActivity ().getApplication ()).setCamPicUri (picUri);
Intent takePicture = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
//May or may not be populated depending on devices.
takePicture.putExtra (MediaStore.EXTRA_OUTPUT, picUri);
getActivity ().startActivityForResult (takePicture, R.id.action_camera_start);
}
And here is my activity getting cam result:
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
super.onActivityResult (requestCode, resultCode, data);
if (requestCode == R.id.action_camera_start)
{
if (resultCode == RESULT_OK)
{
Bitmap pic = null;
Uri picUri = null;
//Some Droid devices (as mine: Acer 500 tablet) leave data Intent null.
if (data == null) {
picUri = ((XeniosMob) getApplication ()).getCamPicUri ();
} else
{
Bundle extras = data.getExtras ();
picUri = (Uri) extras.get (MediaStore.EXTRA_OUTPUT);
}
try
{
pic = Media.getBitmap (getContentResolver (), picUri);
} catch (FileNotFoundException ex)
{
Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, ex);
} catch (IOException ex)
{
Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, ex);
}
//Getting (creating it if necessary) a private directory named app_Pictures
//Using MODE_PRIVATE seems to prefix the directory name provided with "app_".
File dir = getDir (Environment.DIRECTORY_PICTURES, Context.MODE_PRIVATE);
//Query the MediaStore to retrieve generated filename for the capture.
Cursor query = getContentResolver ().query (
picUri,
new String [] {
Media.DISPLAY_NAME,
Media.TITLE
},
null, null, null
);
boolean gotOne = query.moveToFirst ();
File internalFile = null;
if (gotOne)
{
String dn = query.getString (query.getColumnIndexOrThrow (Media.DISPLAY_NAME));
String title = query.getString (query.getColumnIndexOrThrow (Media.TITLE));
query.close ();
//Generated name is a ".jpg" on my device (tablet Acer 500).
//I prefer to work with ".png".
internalFile = new File (dir, dn.subSequence (0, dn.lastIndexOf (".")).toString () + ".png");
internalFile.setReadable (true);
internalFile.setWritable (true);
internalFile.setExecutable (true);
try
{
internalFile.createNewFile ();
//Use an output stream to write picture data to internal file.
FileOutputStream fos = new FileOutputStream (internalFile);
BufferedOutputStream bos = new BufferedOutputStream (fos);
//Use lossless compression.
pic.compress (Bitmap.CompressFormat.PNG, 100, bos);
bos.flush ();
bos.close ();
} catch (FileNotFoundException ex)
{
Logger.getLogger (EvaluationActivity.class.getName()).log (Level.SEVERE, null, ex);
} catch (IOException ex)
{
Logger.getLogger (EvaluationActivity.class.getName()).log (Level.SEVERE, null, ex);
}
}
//Update picture Uri to that of internal file.
((XeniosMob) getApplication ()).setCamPicUri (Uri.fromFile (internalFile));
//Don't keep capture in public storage space (no Android Gallery use)
int delete = getContentResolver ().delete (picUri, null, null);
//rather just keep Uri references here
//visit.add (pic);
//Show the picture in app!
ViewGroup photoLayout = (ViewGroup) findViewById (R.id.layout_photo_area);
ImageView iv = new ImageView (photoLayout.getContext ());
iv.setImageBitmap (pic);
photoLayout.addView (iv, 120, 120);
}
else if (resultCode == RESULT_CANCELED)
{
Toast toast = Toast.makeText (this, "Picture capture has been cancelled.", Toast.LENGTH_LONG);
toast.show ();
}
}
}
Voila! Now we have a truly application private picture file, which name has been generated by the Droid device. And nothing is kept in the public storage area, thus preventing accidental picture manipulation.
here is my working code to save a captured image from the camera to app internal storage:
first, create the file with the desired filename. in this case it is "MyFile.jpg", then start the activity with the intent below. you're callback method(onActivityResult), will be called once complete. After onActivityResult has been called your image should be saved to internal storage. key note: the mode used in openFileOutput needs to be global.. Context.MODE_WORLD_WRITEABLE works fine, i have not tested other modes.
try {
FileOutputStream fos = openFileOutput("MyFile.jpg", Context.MODE_WORLD_WRITEABLE);
fos.close();
File f = new File(getFilesDir() + File.separator + "MyFile.jpg");
startActivityForResult(
new Intent(MediaStore.ACTION_IMAGE_CAPTURE)
.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f))
, IMAGE_CAPTURE_REQUEST_CODE);
}
catch(IOException e) {
}
and in the activity result method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == IMAGE_CAPTURE_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Log.i(TAG, "Image is saved.");
}
}
to retrieve your image:
try {
InputStream is = openFileInput("MyFile.jpg");
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inSampleSize = 4;
Bitmap retrievedBitmap = BitmapFactory.decodeStream(is, null, options);
}
catch(IOException e) {
}
The camera apparently doesn't support writing to internal storage.
Unfortunately this is not mentioned in the documentation.
MediaProvider.java has the following code:
private String generateFileName(boolean internal,
String preferredExtension, String directoryName)
{
// create a random file
String name = String.valueOf(System.currentTimeMillis());
if (internal) {
throw new UnsupportedOperationException(
"Writing to internal storage is not supported.");
// return Environment.getDataDirectory()
// + "/" + directoryName + "/" + name + preferredExtension;
} else {
return Environment.getExternalStorageDirectory()
+ "/" + directoryName + "/" + name + preferredExtension;
}
}
So writing to internal storage has been intentionally disabled for the time being.
Edit - I think you can use binnyb's method as a work-around, but I wouldn't recommend it; I'm not sure if this will continue to work on future versions. I think the intention is to disallow writing to internal storage for media files.
I filed a bug in the Android issue tracker.
Edit - I now understand why binnyb's method works. The camera app is considered to be just another application. It can't write to internal storage if it doesn't have permissions. Setting your file to be world-writable gives other applications permission to write to that file.
I still don't think that this is a very good idea, however, for a few reasons:
You don't generally want other apps writing to your private storage.
Internal storage is quite limited on some phones, and raw camera images are quite large.
If you were planning on resizing the image anyway, then you can read it from external storage and write it yourself to your internal storage.

Saving bitmap to SD card with out compressing it in android

I am using android inbuilt camera to take picture and then attaching the same picture to email, when i am testing this functionality in 1.6 device, i am able name the picture that to be taken by in built camera, but in 2.1, the picture is having a name i.e given by device,
How to give user defined name in 2.1 inbuilt camera images..
to avoid that problem i am saving the image manually but when i try to get the image back through intent as bitmap and then saving it to sd card using compress method
this methods handles result from inbuilt camera
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
File file = new File(Environment.getExternalStorageDirectory()
+ "/test.png");
switch (requestCode)
{
case PHOTO_ACTION:
if (resultCode == RESULT_CANCELED)
{
addPhoto = false;
Toast.makeText(this, "Canceled ", Toast.LENGTH_LONG).show();
break;
} else if (resultCode == RESULT_OK)
{
Bundle b = data.getExtras();
Bitmap bm = (Bitmap) b.get("data");
FileOutputStream out;
try
{
out = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
scanPhoto(file.toString());
out = null;
addPhoto = true;
} catch (Exception e)
{
e.printStackTrace();
addPhoto = false;
}
but when i am storing like this i am getting two images. one with system given name and other with name given by me. but the image one which has user defined is having less resolution so i question is how to save the bitmap with more resolution with out compressing it ..
please help.... me
If you just want to save the bitmap without losing quality try using CompressFormat.PNG instead of JPEG, I've seen people having that problem before. Try changing:
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
with:
bm.compress(Bitmap.CompressFormat.PNG, 100, out);
and see it it helps.
Apart from Rick answer above, make sure your are providing a URI to camera intent where it can save the full image, else it will return thumb image in data parameter of intent.
So it will be like:
Intent photoPickerIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
imgFile = new File("Cache directory","img.png"); //== where you want full size image
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(imgFile));
startActivityForResult(photoPickerIntent, PickPhoto);
This was the error that I was doing.

Categories

Resources