I save a photo from my application in an array of bitmap. Then when I took the pictures I needed, I call the saveAll() function as shown in the code below.
public void saveAll(View view) { for (Bitmap b : arrBitmap) { SystemClock.sleep(1000); try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(convertBitmapToByteArray(b)); fos.close(); Toast.makeText(context, "Picture saved: " + pictureFile.getName(), Toast.LENGTH_SHORT).show(); } catch (Exception e) { } } } private byte[] convertBitmapToByteArray(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(bitmap.getWidth() * bitmap.getHeight()); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); return stream.toByteArray(); } private static File getOutputMediaFile() { File mediaStorageDir = new File("/sdcard/", "JCG Camera"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); return mediaFile; } and the photo is saved very strange, firstly it may not save at all or save everything except the first one or not save at first, but then when I further test the code they may appear ... although every time it shows Toast that everything is saved ... please tell me
what am I doing wrong?
Exception edisplays? - Saidolim