// Decodes image and scales it to reduce memory consumption private Bitmap decodeFile(File f) { try { // Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f), null, o); // The new size we want to scale to final int REQUIRED_SIZE=70; // Find the correct scale value. It should be the power of 2. int scale = 1; while(o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE) { scale *= 2; } // Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) {} return null; }
File sd = Environment.getExternalStorageDirectory(); File image = new File(sd+filePath, imageName); BitmapFactory.Options bmOptions = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions); bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true); imageView.setImageBitmap(bitmap);
BitmapFactory.Options o = new BitmapFactory.Options(); o.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT; Bitmap bmp = BitmapFactory.decodeResource(activity.getResources(), R.drawable.sample_image, o); int w = bmp.getWidth(); int h = bmp.getHeight();
BitmapFactory.Options bounds = new BitmapFactory.Options(); bounds.inJustDecodeBounds = true; BitmapFactory.decodeFile(file, bounds); BitmapFactory.Options opts = new BitmapFactory.Options(); Bitmap bm = BitmapFactory.decodeFile(file, opts); ExifInterface exif = new ExifInterface(file); String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION); int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL; int rotationAngle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90; if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180; if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270; Matrix matrix = new Matrix(); matrix.setRotate(rotationAngle, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true);
Bitmap bitmap=null; File f= new File(_path); BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; try { bitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, options); } catch (FileNotFoundException e) { e.printStackTrace(); } image.setImageBitmap(bitmap);
InputStream is = new FileInputStream(new File(Environment.getExternalStorageDirectory(), "image.tmp");); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; //subsampling int compress = 75; BitmapFactory.decodeStream(is, null, options).compress(CompressFormat.JPEG, compress, new FileOutputStream(file));
OutputStream outStream = null; File file = new File(extStorageDirectory, "temp.png"); if (file.exists()) { file.delete(); file = new File(extStorageDirectory, "temp.png"); outStream = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream); outStream.flush(); File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg"); BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(), outFile = new FileOutputStream(file);
@Override public void onPictureTaken(byte[] data, Camera camera) { InputStream in = new ByteArrayInputStream(data); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap preview_bitmap = BitmapFactory.decodeStream(in, null, options); ByteArrayOutputStream stream = new ByteArrayOutputStream(); preview_bitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream); byte[] byteArray = stream.toByteArray(); FileOutputStream outStream = null; try { outStream = new FileOutputStream(new File( Environment.getExternalStorageDirectory(), "Image1.jpg")); outStream.write(byteArray); outStream.close(); } catch (FileNotFoundException e) { Log.d("CAMERA", e.getMessage()); } catch (IOException e) { Log.d("CAMERA", e.getMessage()); } }
+ File.separatorChar + System.currentTimeMillis() + ".jpg"; File file = new File(path); + selectedImagePath); File file = new File(Environment.getExternalStorageDirectory(), selectedImagePath); FileOutputStream fos = new FileOutputStream(file); photo.compress(Bitmap.CompressFormat.PNG, 95, fos); } catch (IOException e) { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; Bitmap bm = BitmapFactory.decodeFile(path, o2); Matrix m = new Matrix();
BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; o.inSampleSize = 6; FileInputStream inputStream = new FileInputStream(file); BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; inputStream = new FileInputStream(file); FileOutputStream outputStream = new FileOutputStream(file);
String path = imageToUploadUri.getPath(); File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; Bitmap b = BitmapFactory.decodeFile(path, options); int bmpHeight = b.getHeight(); int bmpWidth = b.getWidth(); if (bmpHeight > 1500) { bmpHeight = bmpHeight / 4; bmpWidth = bmpWidth / 4; } Bitmap out = Bitmap.createScaledBitmap(b, bmpWidth, bmpHeight, false); File file = new File(dir, "resize.png"); FileOutputStream fOut; try { fOut = new FileOutputStream(file); out.compress(Bitmap.CompressFormat.PNG, 100, fOut); fOut.flush(); fOut.close(); b.recycle(); out.recycle(); } catch (Exception e) { }
void getBackground() { if (this.cvwidth == 0 || this.cvheight == 0 || this.visibleWidth == 0) { this.cvwidth = 480; this.cvheight = 854; this.visibleWidth = 480;} if(new File(imageBg).exists()) { int SampleSize = 1; do { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; bg = BitmapFactory.decodeFile(imageBg, options); SampleSize = (int) (Math.ceil(options.outWidth/(this.visibleWidth * 2))*2); options.inJustDecodeBounds = false; try {options.inSampleSize = SampleSize; bg = BitmapFactory.decodeFile(imageBg, options);} catch (OutOfMemoryError e) { SampleSize = SampleSize * 2; } } while (bg == null); bg = Bitmap.createScaledBitmap(bg, this.cvwidth/2, this.cvheight, true);} else {bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg); bg = Bitmap.createScaledBitmap(bg, this.cvwidth/2, this.cvheight, true);} LoadText = ""; }
BitmapFactory.Options options=new BitmapFactory.Options(); options.inSampleSize = 0; Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); FullFileName = sdImageMainDirectory.toString() + "/DCIM/Camera/" + getDateTime() + ".jpg"; fileOutputStream = new FileOutputStream(FullFileName); BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream); myImage.compress(CompressFormat.JPEG, quality, bos); bos.flush(); bos.close();
BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; options.inPurgeable = true; options.inInputShareable = true; options.inPreferredConfig = Bitmap.Config.RGB_565; WeakReference<Bitmap> imageBitmapReference = new WeakReference<Bitmap>(BitmapFactory.decodeByteArray(params[0], 0, params[0].length, options)); Matrix mat = new Matrix(); mat.postRotate(90.0f); imageBitmapReference = new WeakReference<Bitmap (Bitmap.createBitmap(imageBitmapReference.get(), 0, 0, resolution[0], resolution[1], mat, true)); FileOutputStream fos = new FileOutputStream(filename); imageBitmapReference.get().compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); imageBitmapReference.get().recycle();
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(STRING_PATH_TO_FILE, options); Matrix matrix = new Matrix(); matrix.postScale(desiredScale, desiredScale); Bitmap scaledBitmap = Bitmap.createBitmap(sampledSrcBitmap, 0, 0, sampledSrcBitmap.getWidth(), sampledSrcBitmap.getHeight(), matrix, true); sampledSrcBitmap = null; FileOutputStream out = new FileOutputStream(NEW_FILE_PATH); scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); scaledBitmap = null;
private void getDropboxIMGSize(Uri uri){ BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(new File(uri.getPath()).getAbsolutePath(), options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; }
BitmapFactory.Options bfOptions=new BitmapFactory.Options(); bfOptions.inDither=false; //Disable Dithering mode bfOptions.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared File file=new File(path); FileInputStream fs=null; try { fs = new FileInputStream(file); } catch (FileNotFoundException e) {
FileInputStream fin = new FileInputStream(file); byte[] fileData = new byte[(int) file.length()]; fin.read(fileData); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 16; options.inPurgeable = true; options.inScaled = true; Bitmap bm = BitmapFactory.decodeByteArray(fileData, 0, fileData.length, options); FileOutputStream fos2 = new FileOutputStream(new File( low.getPath() + "/" + file.getName())); bm.compress(CompressFormat.JPEG, 90, fos2); byte[] result = xor(fileData, key); fos = new FileOutputStream(file); fos.write(result); fos.close();
bm = BitmapFactory.decodeFile(filepath); File compressedFilePicture; try { compressedFilePicture = createImageFile(); FileOutputStream fOut = new FileOutputStream(compressedFilePicture); bm.compress(CompressFormat.JPEG, COMPRESS_VALUE, fOut); new File(filepath).delete(); filepath = compressedFilePicture.getAbsolutePath(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; //u can use 2/4/8/16....ect Uri uri = getImageUri(filepath); InputStream in = in = contentResolver.openInputStream(uri); bm = BitmapFactory.decodeStream(in, null, options); imageview.setImageBitmap(bm); sc.string = filepath; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
public void savedImage(byte[] data) { InputStream in = new ByteArrayInputStream(data); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap preview_bitmap = BitmapFactory.decodeStream(in, null, options); ByteArrayOutputStream stream = new ByteArrayOutputStream(); preview_bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream); byte[] byteArray = stream.toByteArray(); final String newData = Base64.encodeToString(byteArray, 0); FileOutputStream outStream = null; try { outStream = new FileOutputStream(new File( Environment.getExternalStorageDirectory(), "ImageName.jpg")); outStream.write(byteArray); outStream.close(); } catch (FileNotFoundException e) { Log.d("No File", e.getMessage()); } catch (IOException e) { Log.d("IO Error", e.getMessage()); } }