Java Code Examples for android.graphics.Bitmap#CompressFormat
The following examples show how to use
android.graphics.Bitmap#CompressFormat .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapCroppingWorkerTask.java From timecat with Apache License 2.0 | 6 votes |
BitmapCroppingWorkerTask(CropImageView cropImageView, Bitmap bitmap, float[] cropPoints, int degreesRotated, boolean fixAspectRatio, int aspectRatioX, int aspectRatioY, int reqWidth, int reqHeight, CropImageView.RequestSizeOptions options, Uri saveUri, Bitmap.CompressFormat saveCompressFormat, int saveCompressQuality) { mCropImageViewReference = new WeakReference<>(cropImageView); mContext = cropImageView.getContext(); mBitmap = bitmap; mCropPoints = cropPoints; mUri = null; mDegreesRotated = degreesRotated; mFixAspectRatio = fixAspectRatio; mAspectRatioX = aspectRatioX; mAspectRatioY = aspectRatioY; mReqWidth = reqWidth; mReqHeight = reqHeight; mReqSizeOptions = options; mSaveUri = saveUri; mSaveCompressFormat = saveCompressFormat; mSaveCompressQuality = saveCompressQuality; mOrgWidth = 0; mOrgHeight = 0; }
Example 2
Source File: ViewSnapshot.java From ans-android-sdk with GNU General Public License v3.0 | 5 votes |
public synchronized void writeBitmapJSON(Bitmap.CompressFormat format, int quality, OutputStream out) throws IOException { if (null == mCached || mCached.getWidth() == 0 || mCached.getHeight() == 0) { out.write("null".getBytes()); } else { out.write('"'); final Base64OutputStream imageOut = new Base64OutputStream(out, Base64.NO_WRAP); mCached.compress(Bitmap.CompressFormat.PNG, 100, imageOut); imageOut.flush(); out.write('"'); } }
Example 3
Source File: ImageUtil.java From YiBo with Apache License 2.0 | 5 votes |
private static Bitmap.CompressFormat getCompressFormat(File file) { Bitmap.CompressFormat format = null; try { String fileExtension = FileUtil.getFileExtensionFromName(file.getName()); format = Bitmap.CompressFormat.valueOf(fileExtension); } catch (Exception e) { format = Bitmap.CompressFormat.JPEG; } return format; }
Example 4
Source File: CropParameters.java From EasyPhotos with Apache License 2.0 | 5 votes |
public CropParameters(int maxResultImageSizeX, int maxResultImageSizeY, Bitmap.CompressFormat compressFormat, int compressQuality, Uri imageInputUri, String imageOutputPath, ExifInfo exifInfo) { mMaxResultImageSizeX = maxResultImageSizeX; mMaxResultImageSizeY = maxResultImageSizeY; mCompressFormat = compressFormat; mCompressQuality = compressQuality; mImageInputUri = imageInputUri; mImageOutputPath = imageOutputPath; mExifInfo = exifInfo; }
Example 5
Source File: BitmapUtil.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
/** * Store the bitmap as a file. * * @param bitmap to store. * @param format bitmap format. * @param quality the quality of the compressed bitmap. * @return the compressed bitmap file. */ public static boolean storeAsFile(Bitmap bitmap, File file, Bitmap.CompressFormat format, int quality) { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file)); return bitmap.compress(format, quality, out); } catch (FileNotFoundException e) { Log.e(TAG, "no such file for saving bitmap: ", e); return false; } finally { CloseableUtils.close(out); } }
Example 6
Source File: FileRecyclerViewAdapter.java From faceswap with Apache License 2.0 | 5 votes |
public BitmapWorkerTask(ImageView imageView, Bitmap.CompressFormat format) { // Use a WeakReference to ensure the ImageView can be garbage collected imageView.setBackgroundDrawable(imageView.getContext() .getResources().getDrawable(R.drawable.fplib_rectangle)); imageViewReference = new WeakReference<ImageView>(imageView); mFormat = format; }
Example 7
Source File: BitmapUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 重新编码 Bitmap * @param bitmap 需要重新编码的 bitmap * @param format 编码后的格式 如 Bitmap.CompressFormat.PNG * @param quality 质量 * @param options {@link BitmapFactory.Options} * @return 重新编码后的图片 */ public static Bitmap recode(final Bitmap bitmap, final Bitmap.CompressFormat format, @IntRange(from = 0, to = 100) final int quality, final BitmapFactory.Options options) { if (isEmpty(bitmap) || format == null) return null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, quality, baos); byte[] data = baos.toByteArray(); return BitmapFactory.decodeByteArray(data, 0, data.length, options); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "recode"); } return null; }
Example 8
Source File: UploadBitmapAsyncTask.java From Android-SDK with MIT License | 4 votes |
void executeThis( Bitmap bitmap, Bitmap.CompressFormat compressFormat, int quality, String name, String path, AsyncCallback<BackendlessFile> responder ) { executeThis( bitmap, compressFormat, quality, name, path, false, responder ); }
Example 9
Source File: KCWebImageDownloader.java From kerkee_android with GNU General Public License v3.0 | 4 votes |
private void writeBitmapToFile(String targetPath, InputStream inputStream) throws IOException { File file = new File(targetPath); synchronized (object) { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } } String name = file.getName().toLowerCase(); Bitmap.CompressFormat format; if (name.contains("jpg") || name.contains("jpeg")) { format = Bitmap.CompressFormat.JPEG; } else if (name.contains("png")) { format = Bitmap.CompressFormat.PNG; } else if (name.contains("webp")) { if (Build.VERSION.SDK_INT >= 14) format = Bitmap.CompressFormat.WEBP; else format = Bitmap.CompressFormat.JPEG; } else { format = Bitmap.CompressFormat.JPEG; } //write to file try { Bitmap bitmap = BitmapFactory.decodeStream(inputStream); FileOutputStream fileOutputStream = new FileOutputStream(file); OutputStream fileOut = new BufferedOutputStream(fileOutputStream); bitmap.compress(format, 100, fileOut); bitmap.recycle(); fileOut.flush(); fileOut.close(); fileOutputStream.close(); } catch (Exception e) { if (KCLog.DEBUG) { KCLog.e(e); } } catch (OutOfMemoryError error) { if (KCLog.DEBUG) { KCLog.e(error); } } }
Example 10
Source File: CaptureSettings.java From SimpleSmsRemote with MIT License | 4 votes |
ImageFormat(Bitmap.CompressFormat bitmapCompressFormat, String fileExtension) { this.bitmapCompressFormat = bitmapCompressFormat; this.fileExtension = fileExtension; }
Example 11
Source File: CropView.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@SuppressLint("WrongThread") private void editBitmap(String path, Bitmap b, Canvas canvas, Bitmap canvasBitmap, Bitmap.CompressFormat format, float scale, ArrayList<VideoEditedInfo.MediaEntity> entities, boolean clear) { try { if (clear) { canvasBitmap.eraseColor(0); } if (b == null) { b = BitmapFactory.decodeFile(path); } float sc = Math.max(b.getWidth(), b.getHeight()) / (float) Math.max(bitmap.getWidth(), bitmap.getHeight()); Matrix matrix = new Matrix(); matrix.postTranslate(-b.getWidth() / 2, -b.getHeight() / 2); matrix.postScale(1.0f / sc, 1.0f / sc); matrix.postRotate(state.getOrientationOnly()); state.getConcatMatrix(matrix); matrix.postScale(scale, scale); matrix.postTranslate(canvasBitmap.getWidth() / 2, canvasBitmap.getHeight() / 2); canvas.drawBitmap(b, matrix, new Paint(FILTER_BITMAP_FLAG)); FileOutputStream stream = new FileOutputStream(new File(path)); canvasBitmap.compress(format, 87, stream); stream.close(); if (entities != null && !entities.isEmpty()) { float[] point = new float[4]; float newScale = 1.0f / sc * scale * state.scale; for (int a = 0, N = entities.size(); a < N; a++) { VideoEditedInfo.MediaEntity entity = entities.get(a); point[0] = entity.x * b.getWidth() + entity.viewWidth * entity.scale / 2; point[1] = entity.y * b.getHeight() + entity.viewHeight * entity.scale / 2; point[2] = entity.textViewX * b.getWidth(); point[3] = entity.textViewY * b.getHeight(); matrix.mapPoints(point); float widthScale = b.getWidth() / (float) canvasBitmap.getWidth(); newScale *= widthScale; if (entity.type == 0) { entity.viewWidth = entity.viewHeight = canvasBitmap.getWidth() / 2; } else if (entity.type == 1) { entity.fontSize = canvasBitmap.getWidth() / 9; } entity.scale *= newScale; entity.x = (point[0] - entity.viewWidth * entity.scale / 2) / canvasBitmap.getWidth(); entity.y = (point[1] - entity.viewHeight * entity.scale / 2) / canvasBitmap.getHeight(); entity.textViewX = point[2] / canvasBitmap.getWidth(); entity.textViewY = point[3] / canvasBitmap.getHeight(); entity.width = entity.viewWidth * entity.scale / canvasBitmap.getWidth(); entity.height = entity.viewHeight * entity.scale / canvasBitmap.getHeight(); entity.textViewWidth = entity.viewWidth / (float) canvasBitmap.getWidth(); entity.textViewHeight = entity.viewHeight / (float) canvasBitmap.getHeight(); entity.rotation -= (state.getRotation() + state.getOrientationOnly()) * (Math.PI / 180); } } b.recycle(); } catch (Throwable e) { FileLog.e(e); } }
Example 12
Source File: CropImageView.java From Lassi-Android with MIT License | 4 votes |
/** * Gets the cropped image based on the current crop window.<br> * If (reqWidth,reqHeight) is given AND image is loaded from URI cropping will try to use sample * size to fit in the requested width and height down-sampling if possible - optimization to get * best size to quality.<br> * The result will be invoked to listener set by {@link * #setOnCropImageCompleteListener(OnCropImageCompleteListener)}. * * @param reqWidth the width to resize the cropped image to (see options) * @param reqHeight the height to resize the cropped image to (see options) * @param options the resize method to use on the cropped bitmap * @param saveUri optional: to save the cropped image to * @param saveCompressFormat if saveUri is given, the given compression will be used for saving * the image * @param saveCompressQuality if saveUri is given, the given quality will be used for the * compression. */ public void startCropWorkerTask( int reqWidth, int reqHeight, RequestSizeOptions options, Uri saveUri, Bitmap.CompressFormat saveCompressFormat, int saveCompressQuality) { Bitmap bitmap = mBitmap; if (bitmap != null) { mImageView.clearAnimation(); BitmapCroppingWorkerTask currentTask = mBitmapCroppingWorkerTask != null ? mBitmapCroppingWorkerTask.get() : null; if (currentTask != null) { // cancel previous cropping currentTask.cancel(true); } reqWidth = options != RequestSizeOptions.NONE ? reqWidth : 0; reqHeight = options != RequestSizeOptions.NONE ? reqHeight : 0; int orgWidth = bitmap.getWidth() * mLoadedSampleSize; int orgHeight = bitmap.getHeight() * mLoadedSampleSize; if (mLoadedImageUri != null && (mLoadedSampleSize > 1 || options == RequestSizeOptions.SAMPLING)) { mBitmapCroppingWorkerTask = new WeakReference<>( new BitmapCroppingWorkerTask( this, mLoadedImageUri, getCropPoints(), mDegreesRotated, orgWidth, orgHeight, mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY(), reqWidth, reqHeight, mFlipHorizontally, mFlipVertically, options, saveUri, saveCompressFormat, saveCompressQuality)); } else { mBitmapCroppingWorkerTask = new WeakReference<>( new BitmapCroppingWorkerTask( this, bitmap, getCropPoints(), mDegreesRotated, mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY(), reqWidth, reqHeight, mFlipHorizontally, mFlipVertically, options, saveUri, saveCompressFormat, saveCompressQuality)); } mBitmapCroppingWorkerTask.get().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); setProgressBarVisibility(); } }
Example 13
Source File: CropParameters.java From EasyPhotos with Apache License 2.0 | 4 votes |
public Bitmap.CompressFormat getCompressFormat() { return mCompressFormat; }
Example 14
Source File: Compressor.java From youqu_master with Apache License 2.0 | 4 votes |
public Builder setCompressFormat(Bitmap.CompressFormat compressFormat) { compressor.compressFormat = compressFormat; return this; }
Example 15
Source File: BaseDiskCache.java From BigApp_WordPress_Android with Apache License 2.0 | 4 votes |
public void setCompressFormat(Bitmap.CompressFormat compressFormat) { this.compressFormat = compressFormat; }
Example 16
Source File: ImageTool.java From sdk3rd with Apache License 2.0 | 4 votes |
public static byte[] toBytes(Bitmap bitmap, Bitmap.CompressFormat format) { ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(format, 100, os); return os.toByteArray(); }
Example 17
Source File: PurgeableBitmapView.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
private byte[] generateBitstream(Bitmap src, Bitmap.CompressFormat format, int quality) { ByteArrayOutputStream os = new ByteArrayOutputStream(); src.compress(format, quality, os); return os.toByteArray(); }
Example 18
Source File: BitmapUtils.java From FastAndroid with Apache License 2.0 | 2 votes |
/** * bitmap 转 byteArr * * @param bitmap bitmap 对象 * @param format 格式 * @return 字节数组 */ public static byte[] bitmap2Bytes(@NonNull Bitmap bitmap, @NonNull Bitmap.CompressFormat format) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, 100, baos); return baos.toByteArray(); }
Example 19
Source File: MediaRow.java From geopackage-android with MIT License | 2 votes |
/** * Set the data from a bitmap * * @param bitmap bitmap * @param format compress format * @param quality quality * @throws IOException upon failure * @since 3.2.0 */ public void setData(Bitmap bitmap, Bitmap.CompressFormat format, int quality) throws IOException { setData(BitmapConverter.toBytes(bitmap, format, quality)); }
Example 20
Source File: ImageUtils.java From DevUtils with Apache License 2.0 | 2 votes |
/** * Bitmap 转换成 byte[] * @param bitmap 待转换图片 * @param format 如 Bitmap.CompressFormat.PNG * @return byte[] */ public static byte[] bitmapToByte(final Bitmap bitmap, final Bitmap.CompressFormat format) { return bitmapToByte(bitmap, 100, format); }