// save image public void saveBitmap(Bitmap bm) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HHmm", Locale.UK); Date now = new Date(); String fileName = formatter.format(now) + ".png"; File f; try { cameraPath = Environment.getExternalStorageDirectory().toString() + File.separator + "Pictures" + File.separator + fileName; f = new File(cameraPath); FileOutputStream out = new FileOutputStream(f); bm.compress(Bitmap.CompressFormat.PNG, 90, out); out.flush(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { uri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bm, null, null)); // MediaStore.Images.Media.insertImage(this.getContentResolver(), cameraPath, fileName, null); // CameraActivity.this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, // Uri.fromFile(new File(cameraPath)))); } catch (Exception e) { e.printStackTrace(); } }
@Override protected String doInBackground(Bitmap... params) { String result = "图片保存失败"; try { String sdcard = Environment.getExternalStorageDirectory().toString(); String fileName = System.currentTimeMillis() + ".png"; File file = new File(sdcard + "/Download", fileName); if (!file.exists()) { file.mkdirs(); } File imageFile = new File(file.getAbsolutePath(), new Date().getTime() + ".jpg"); FileOutputStream fileOutputStream = null; fileOutputStream = new FileOutputStream(imageFile); Bitmap image = params[0]; image.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); result = String.format("图片保存到%s", file.getAbsolutePath()); // 其次把文件插入到系统图库 MediaStore.Images.Media.insertImage( mContext.getContentResolver(), file.getAbsolutePath(), fileName, null); // 最后通知图库更新 mContext.sendBroadcast( new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getAbsolutePath()))); } catch (Exception e) { e.printStackTrace(); } return result; }
// 保存并通知系统图库更新 public void saveImageToGallery(Bitmap bmp, String fileName) { // 首先保存图片 File appDir = new File(ALBUM_PATH); if (!appDir.exists()) { appDir.mkdir(); } File file = new File(ALBUM_PATH, fileName); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // 其次把文件插入到系统图库 try { MediaStore.Images.Media.insertImage( PictureActivity.this.getContentResolver(), file.getAbsolutePath(), fileName, null); } catch (FileNotFoundException e) { e.printStackTrace(); } // 最后通知图库更新 String path = ALBUM_PATH + fileName; System.out.println("path : " + path); PictureActivity.this.sendBroadcast( new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path))); }
/* (non-Javadoc) * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_EVOLUTION: this.showDialog(DIALOG_SELECT_TIME_STEP); return true; case MENU_HOME: Intent i = new Intent(this, OmbreActivity.class); this.startActivity(i); return true; case MENU_SAVE: Bitmap bitmap = Bitmap.createBitmap(this.controller.getBitmap()); Canvas canvas = new Canvas(bitmap); // Draw the shadows new ResultDrawable(this.controller).draw(canvas); // Draw the time of the simulation Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setTextSize(24); canvas.drawText(dateFormat.format(this.controller.getTime().getTime()), 5, 29, paint); MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmap, "Result", "Result"); return true; } return super.onOptionsItemSelected(item); }
private void shareComicImage() { Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); Bitmap mBitmap = mComicMap.get(sFavoriteIndex).getBitmap(); try { String path = MediaStore.Images.Media.insertImage( getActivity().getContentResolver(), mBitmap, "Image Description", null); share.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)); } catch (Exception e) { try { File cachePath = new File(getActivity().getCacheDir(), "images"); cachePath.mkdirs(); // don't forget to make the directory FileOutputStream stream = new FileOutputStream(cachePath + "/image.png"); mBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); stream.close(); File imagePath = new File(getActivity().getCacheDir(), "images"); File newFile = new File(imagePath, "image.png"); Uri contentUri = FileProvider.getUriForFile( getActivity(), "com.gadgetmonks.carntoonage.fileprovider", newFile); share.putExtra(Intent.EXTRA_STREAM, contentUri); } catch (IOException e2) { e.printStackTrace(); } } if (PrefHelper.shareAlt()) { share.putExtra(Intent.EXTRA_TEXT, PrefHelper.getAlt(sFavorites[sFavoriteIndex])); } startActivity(Intent.createChooser(share, this.getResources().getString(R.string.share_image))); }
@TargetApi(CAMERA_2_API_LIMIT) @Override public void run() { ByteBuffer buffer = mImage.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.remaining()]; buffer.get(bytes); FileOutputStream output = null; try { output = new FileOutputStream(mFile); output.write(bytes); Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss"); final String timestampFilename = dateFormat.format(date); // http://stackoverflow.com/a/8722494/4326052 String imagePath = new File(mActivity.getExternalFilesDir(null), timestampFilename + ".jpg") .getAbsolutePath(); MediaStore.Images.Media.insertImage( mActivity.getContentResolver(), bitmap, timestampFilename, "Picture taken by shoutake"); } catch (IOException e) { e.printStackTrace(); } finally { mImage.close(); if (null != output) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public static Uri getImageUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); return Uri.parse(path); }
/** * @param context * @param bitmap * @return * @brief methods for getting file uri from bitmap */ public static Uri getUriFromBitmap(Context context, Bitmap bitmap) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage( context.getContentResolver(), bitmap, "image_share", null); return Uri.parse(path); }
public static Uri getImage(ImageView image, ContentResolver contentResolver) { MediaStoreHelper.initMediaDir(); Drawable mDrawable = image.getDrawable(); Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap(); String path = MediaStore.Images.Media.insertImage(contentResolver, mBitmap, "Image Description", null); Uri uri = Uri.parse(path); return uri; }
public static boolean saveImageToGallery(Bitmap bitmap, Context context) { boolean flag = false; String result = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "", ""); if (result != null) { context.sendBroadcast( new Intent( Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); flag = true; } else { flag = false; } return flag; }
private String saveImage(Bitmap bm, int id, LinphoneChatMessage message) { try { String path = Environment.getExternalStorageDirectory().toString(); if (!path.endsWith("/")) path += "/"; path += "Pictures/"; File directory = new File(path); directory.mkdirs(); String filename = getString(R.string.picture_name_format).replace("%s", String.valueOf(id)); File file = new File(path, filename); OutputStream fOut = null; fOut = new FileOutputStream(file); bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut); fOut.flush(); fOut.close(); if (useLinphoneMessageStorage) { // Update url path in liblinphone database if (message == null) { LinphoneChatMessage[] history = chatRoom.getHistory(); for (LinphoneChatMessage msg : history) { if (msg.getStorageId() == id) { message = msg; break; } } } message.setExternalBodyUrl(path + filename); chatRoom.updateUrl(message); } MediaStore.Images.Media.insertImage( getActivity().getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName()); return file.getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); } return null; }
@Override public void saveImage(PictureTransaction xact, Bitmap bitmap) { String path = MediaStore.Images.Media.insertImage( getActivity().getContentResolver(), bitmap, getPhotoFilename(), null); if (path == null) { final Activity activity = getActivity(); activity.runOnUiThread( new Runnable() { @Override public void run() { Toast.makeText( activity, getString(R.string.photo_save_error_toast), Toast.LENGTH_SHORT) .show(); mTakePictureBtn.setEnabled(true); mProgressDialog.dismiss(); } }); } else { Uri contentUri = Uri.parse(path); final Image image = getImageFromContentUri(contentUri); // run the media scanner service // MediaScannerConnection.scanFile(getActivity(), new String[]{path}, new // String[]{"image/jpeg"}, null); getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri)); // the current method is an async. call. // so make changes to the UI on the main thread. getActivity() .runOnUiThread( new Runnable() { @Override public void run() { ((ImagePickerActivity) getActivity()).addImage(image); mTakePictureBtn.setEnabled(true); mProgressDialog.dismiss(); } }); } }
public void initShareIntent() { String path = MediaStore.Images.Media.insertImage( mContext.getContentResolver(), mBitmap, "Image Description", null); Intent shareIntent = new Intent(Intent.ACTION_SEND); // shareIntent.setType("image/*"); try { shareIntent.putExtra( Intent.EXTRA_TEXT, mCharacter.getName() + "\n" + mCharacter.getDescription()); Uri bmpUri = Uri.parse(path); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); // startActivity(Intent.createChooser(shareIntent, "How do you want to share?")); // return shareIntent; } catch (NullPointerException e) { // return shareIntent; startActivity(Intent.createChooser(shareIntent, "How do you want to share?")); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == GCAccountStore.AUTHENTICATION_REQUEST_CODE) { GCAccounts.all(getApplicationContext(), new AccountsCallback()).executeAsync(); } if (requestCode == PhotosIntentWrapper.ACTIVITY_FOR_RESULT_STREAM_KEY) { finish(); } else if (requestCode == Constants.CAMERA_PIC_REQUEST) { // Bitmap image = (Bitmap) data.getExtras().get("data"); String path = ""; File tempFile = AppUtil.getTempFile(getApplicationContext()); if (AppUtil.hasImageCaptureBug() == false && tempFile.length() > 0) { try { android.provider.MediaStore.Images.Media.insertImage( getContentResolver(), tempFile.getAbsolutePath(), null, null); tempFile.delete(); path = MediaDAO.getLastPhotoFromCameraPhotos(getApplicationContext()).toString(); } catch (FileNotFoundException e) { Log.d(TAG, "", e); } } else { Log.e(TAG, "Bug " + data.getData().getPath()); path = Uri.fromFile(new File(AppUtil.getPath(getApplicationContext(), data.getData()))) .toString(); } Log.d(TAG, path); final GCAccountMediaModel model = new GCAccountMediaModel(); model.setLargeUrl(path); model.setThumbUrl(path); model.setUrl(path); IntentUtil.deliverDataToInitialActivity(this, model, ppWrapper.getChuteId()); } } }
@Override public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) { if (LinphoneActivity.isInstanciated() && state != LinphoneChatMessage.State.InProgress) { if (msg != null) { LinphoneActivity.instance().onMessageStateChanged(sipUri, msg.getText(), state.toInt()); } invalidate(); } if (state == State.FileTransferDone) { if (mDownloadedImageStream != null) { byte[] bytes = mDownloadedImageStream.toByteArray(); Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, mDownloadedImageStreamSize); String path = msg.getExternalBodyUrl(); String fileName = path.substring(path.lastIndexOf("/") + 1); String url = MediaStore.Images.Media.insertImage( getActivity().getContentResolver(), bm, fileName, null); if (url != null) { msg.setAppData(url); } mDownloadedImageStream = null; mDownloadedImageStreamSize = 0; } else if (mUploadingImageStream != null) { mUploadingImageStream = null; } } if (state == State.FileTransferDone || state == State.FileTransferError) { uploadLayout.setVisibility(View.GONE); textLayout.setVisibility(View.VISIBLE); progressBar.setProgress(0); currentMessageInFileTransferUploadState = null; } invalidate(); }
public File saveImage(Bitmap thePic, String fileName, Context context) { OutputStream fOut = null; File m = new File(Environment.getExternalStorageDirectory(), "/SaleZone/media"); if (!m.exists()) { m.mkdirs(); } else if (m.exists()) { m.delete(); m.mkdirs(); } String strDirectory = m.toString(); File f = new File(m, fileName); log("output directory:" + strDirectory); try { fOut = new FileOutputStream(f); /** Compress image * */ thePic.compress(Bitmap.CompressFormat.JPEG, 85, fOut); fOut.flush(); fOut.close(); /** Update image to gallery * */ MediaStore.Images.Media.insertImage( context.getContentResolver(), f.getAbsolutePath(), f.getName(), f.getName()); log("IMAGE SAVED........"); // SAVE FACE IMAGE LOCATION log("ABSOLUTE PATH:" + f.getAbsolutePath()); log("FILE NAME:" + f.getName()); } catch (Exception e) { e.printStackTrace(); } return f; }
public static void saveImage(Context context, String filename, byte[] content) { // Construimos un bitmap, con el tamaño modificado, a partir del contenido de la imagen. // Se coloca como tamaño 300dp, aunque este parámetro podría hacerse configurable. Bitmap b = Utils.decodeBitmapSize(content, 300); // Instanciamos el fichero donde vamos a almacenar la imagen File path = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), filename); // Este flujo será el que usemos para almacenar la imagen en el fichero BufferedOutputStream bos = null; try { bos = new BufferedOutputStream(new FileOutputStream(path)); // Este método es el que almacena la imagen b.compress(Bitmap.CompressFormat.JPEG, 100, bos); Log.d("GUARDANDO FICHERO", "Almacenando el fichero en la ruta " + path.getAbsolutePath()); // Vaciamos el flujo bos.flush(); // Cerramos los flujos correspondientes bos.close(); // Registramos la imagen en la galería MediaStore.Images.Media.insertImage( context.getContentResolver(), path.getAbsolutePath(), path.getName(), path.getName()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_share: ImageView siv = (ImageView) findViewById(R.id.img); Drawable mDrawable = siv.getDrawable(); Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap(); String path = MediaStore.Images.Media.insertImage( getContentResolver(), mBitmap, "Image Description", null); Uri uri = Uri.parse(path); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/*"); // Launch sharing dialog for image startActivity(Intent.createChooser(shareIntent, "Share Image")); return true; default: return super.onOptionsItemSelected(item); } }
// Función a la que se salta después de la introducción de datos en otros Activities protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Si el código es cero, se trata de exportar la imagen en formato JPEG if (requestCode == 0) { if (resultCode == RESULT_OK) { String nombre = data.getStringExtra("nombre"); mySimpleXYPlot.setDrawingCacheEnabled(true); int width = mySimpleXYPlot.getWidth(); int height = mySimpleXYPlot.getHeight(); mySimpleXYPlot.measure(width, height); Bitmap bmp = Bitmap.createBitmap(mySimpleXYPlot.getDrawingCache()); // Acceso a SDCard String path = Environment.getExternalStorageDirectory().toString(); OutputStream fOut = null; File file = new File(path + "/FC_aplication/", nombre + ".JPEG"); try { fOut = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fOut); fOut.flush(); fOut.close(); MediaStore.Images.Media.insertImage( getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName()); Toast.makeText(Poincare.this, "Señal exportada en formato JPEG", Toast.LENGTH_LONG) .show(); } catch (Exception e) { } } } // Si el código es cero, se trata de exportar la imagen en formato PNG else if (requestCode == 1) { if (resultCode == RESULT_OK) { String nombre = data.getStringExtra("nombre"); mySimpleXYPlot.setDrawingCacheEnabled(true); int width1 = mySimpleXYPlot.getWidth(); int height1 = mySimpleXYPlot.getHeight(); mySimpleXYPlot.measure(width1, height1); // Acceso a SDCard Bitmap bmp1 = Bitmap.createBitmap(mySimpleXYPlot.getDrawingCache()); String path1 = Environment.getExternalStorageDirectory().toString(); OutputStream fOut1 = null; File file1 = new File(path1 + "/FC_aplication/", nombre + ".PNG"); try { fOut1 = new FileOutputStream(file1); bmp1.compress(Bitmap.CompressFormat.PNG, 100, fOut1); fOut1.flush(); fOut1.close(); MediaStore.Images.Media.insertImage( getContentResolver(), file1.getAbsolutePath(), file1.getName(), file1.getName()); Toast.makeText(Poincare.this, "Señal exportada en formato PNG", Toast.LENGTH_LONG).show(); } catch (Exception e) { } } } }
@Override public void onPictureTaken(byte[] data, Camera camera) { Intent intent = new Intent(); OutputStream stream = null; try { final Map<String, String> propertyMap = getActualPropertyMap(); if (propertyMap == null) { throw new RuntimeException("Camera property map is undefined"); } String outputFormat = propertyMap.get("outputFormat"); if (propertyMap.get("deprecated") == null || propertyMap.get("deprecated").equalsIgnoreCase("false")) { propertyMap.put("deprecated", "false"); deprecated_take_pic = false; } else deprecated_take_pic = true; if (propertyMap.containsKey("captureSound")) { Runnable music = new Runnable() { public void run() { playMusic(propertyMap.get("captureSound")); } }; ExecutorService exec = Executors.newSingleThreadExecutor(); exec.submit(music); } String filePath = null; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_hhmmss"); if (!propertyMap.containsKey("fileName")) { filePath = "/sdcard/DCIM/Camera/IMG_" + dateFormat.format(new Date(System.currentTimeMillis())); userFilePath = filePath; } else { filePath = propertyMap.get("fileName"); userFilePath = filePath; if (filePath.contains("\\")) { intent.putExtra("error", "Invalid file path"); } } Uri resultUri = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); Matrix m = new Matrix(); android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(getCameraIndex(), info); if (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT && OrientationListnerService.mRotation == 90) { m.postRotate(270); } else if (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT && OrientationListnerService.mRotation == 270) { m.postRotate(90); } else { m.postRotate(OrientationListnerService.mRotation); } bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if (outputFormat.equalsIgnoreCase("dataUri")) { Logger.T(TAG, "outputFormat: " + outputFormat); // filePath = getTemporaryPath(filePath)+ ".jpg"; if (Boolean.parseBoolean(propertyMap.get("saveToDeviceGallery"))) { ContentResolver contentResolver = ContextFactory.getContext().getContentResolver(); Logger.T(TAG, "Image size: " + bitmap.getWidth() + "X" + bitmap.getHeight()); propertyMap.put("DeviceGallery_Key", "DeviceGallery_Value"); String strUri = null; if (!propertyMap.containsKey("fileName")) { strUri = MediaStore.Images.Media.insertImage( contentResolver, bitmap, "IMG_" + dateFormat.format(new Date(System.currentTimeMillis())), "Camera"); } else { strUri = MediaStore.Images.Media.insertImage( contentResolver, bitmap, new File(propertyMap.get("fileName")).getName(), "Camera"); } if (strUri != null) { resultUri = Uri.parse(strUri); } else { throw new RuntimeException("Failed to save camera image to Gallery"); } } else { if (userFilePath.contains("sdcard")) { Boolean isSDPresent = android.os.Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_MOUNTED); if (isSDPresent) { byte[] byteArray = null; int lastIndex = userFilePath.lastIndexOf("/"); String subfolderName = userFilePath.replaceAll("/sdcard", ""); String folderName = subfolderName.substring( subfolderName.indexOf("/") + 1, subfolderName.lastIndexOf("/")); String file_name = userFilePath.substring(lastIndex + 1, userFilePath.length()); File directory = new File( Environment.getExternalStorageDirectory() + File.separator + folderName); boolean flag = directory.mkdirs(); stream = new FileOutputStream(directory + File.separator + file_name + ".jpg"); resultUri = Uri.fromFile(new File(directory + File.separator + file_name + ".jpg")); if (bitmap != null) { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytestream); byteArray = bytestream.toByteArray(); stream.write(byteArray); stream.flush(); stream.close(); } } } else { stream = new FileOutputStream(filePath); resultUri = Uri.fromFile(new File(filePath)); byte[] byteArray = null; if (bitmap != null) { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytestream); byteArray = bytestream.toByteArray(); stream.write(byteArray); stream.flush(); stream.close(); } } // CameraRhoListener.getInstance().copyImgAsUserChoice(filePath); } byte[] byteArray = null; stream = new FileOutputStream(filePath); if (bitmap != null) { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytestream); byteArray = bytestream.toByteArray(); stream.write(byteArray); stream.flush(); stream.close(); } StringBuilder dataBuilder = new StringBuilder(); dataBuilder.append("data:image/jpeg;base64,"); dataBuilder.append(Base64.encodeToString(byteArray, false)); propertyMap.put("captureUri", dataBuilder.toString()); propertyMap.put("dataURI", "datauri_value"); Logger.T(TAG, dataBuilder.toString()); intent.putExtra("IMAGE_WIDTH", bitmap.getWidth()); intent.putExtra("IMAGE_HEIGHT", bitmap.getHeight()); mPreviewActivity.setResult(Activity.RESULT_OK, intent); } else if (outputFormat.equalsIgnoreCase("image")) { // filePath = getTemporaryPath(filePath)+ ".jpg"; Logger.T(TAG, "outputFormat: " + outputFormat + ", path: " + filePath); if (Boolean.parseBoolean(propertyMap.get("saveToDeviceGallery"))) { ContentResolver contentResolver = ContextFactory.getContext().getContentResolver(); Logger.T(TAG, "Image size: " + bitmap.getWidth() + "X" + bitmap.getHeight()); propertyMap.put("DeviceGallery_Key", "DeviceGallery_Value"); String strUri = null; if (!propertyMap.containsKey("fileName")) strUri = MediaStore.Images.Media.insertImage( contentResolver, bitmap, "IMG_" + dateFormat.format(new Date(System.currentTimeMillis())), "Camera"); else strUri = MediaStore.Images.Media.insertImage( contentResolver, bitmap, new File(propertyMap.get("fileName")).getName(), "Camera"); if (strUri != null) { resultUri = Uri.parse(strUri); } else { throw new RuntimeException("Failed to save camera image to Gallery"); } } else { stream = new FileOutputStream(filePath); resultUri = Uri.fromFile(new File(filePath)); byte[] byteArray = null; if (bitmap != null) { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytestream); byteArray = bytestream.toByteArray(); stream.write(byteArray); stream.flush(); stream.close(); } } intent.putExtra(MediaStore.EXTRA_OUTPUT, resultUri); intent.putExtra("IMAGE_WIDTH", bitmap.getWidth()); intent.putExtra("IMAGE_HEIGHT", bitmap.getHeight()); mPreviewActivity.setResult(Activity.RESULT_OK, intent); } } catch (Throwable e) { Logger.E(TAG, e); if (stream != null) { try { stream.close(); } catch (Throwable e1) { // Do nothing } } intent.putExtra("error", e.getMessage()); mPreviewActivity.setResult(Activity.RESULT_CANCELED, intent); } if (bitmap != null) { bitmap.recycle(); bitmap = null; System.gc(); } mPreviewActivity.finish(); }