Java Code Examples for android.graphics.Bitmap.CompressFormat

The following are Jave code examples for showing how to use CompressFormat of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: youkes_browser   File: HelpUtils.java   View Source Code Vote up 6 votes
/**
 * 压缩发送到服务器的图片
 * @param origPath 原始图片路径
 * @param widthLimit 图片宽度限制
 * @param heightLimit 图片高度限制
 * @param format 图片格式
 * @param quality 图片压缩率
 * @param authorityDir 图片目录
 * @param outPath 图片详细目录
 * @return
 */
public static boolean createThumbnailFromOrig(String origPath,
                                              int widthLimit, int heightLimit, Bitmap.CompressFormat format,
                                              int quality, String authorityDir, String outPath) {
    Bitmap bitmapThumbNail = extractThumbNail(origPath, widthLimit, heightLimit, false);
    if(bitmapThumbNail == null) {
        return false;
    }

    try {
        saveImageFile(bitmapThumbNail, quality, format, authorityDir, outPath);
        return true;
    } catch (IOException e) {
        LogUtil.e(TAG,  "create thumbnail from orig failed: " + outPath);
    }
    return false;
}
 
Example 2
Project: AndroidOCRFforID   File: BitmapCropTask.java   View Source Code Vote up 6 votes
public BitmapCropTask(@NonNull Context context, @Nullable Bitmap viewBitmap,
                      @NonNull RectF cropRect, @NonNull RectF currentImageRect,
                      float currentScale, float currentAngle,
                      int maxResultImageSizeX, int maxResultImageSizeY,
                      @NonNull Bitmap.CompressFormat compressFormat, int compressQuality,
                      @NonNull Uri outputUri, @Nullable BitmapCropCallback cropCallback) {

    mContext = context;

    mViewBitmap = viewBitmap;
    mCropRect = cropRect;
    mCurrentImageRect = currentImageRect;

    mCurrentScale = currentScale;
    mCurrentAngle = currentAngle;
    mMaxResultImageSizeX = maxResultImageSizeX;
    mMaxResultImageSizeY = maxResultImageSizeY;

    mCompressFormat = compressFormat;
    mCompressQuality = compressQuality;

    mOutputUri = outputUri;

    mCropCallback = cropCallback;
}
 
Example 3
Project: AndroidOCRFforID   File: UCropActivity.java   View Source Code Vote up 6 votes
/**
 * This method extracts {@link com.yalantis.ucrop.UCrop.Options #optionsBundle} from incoming intent
 * and setups Activity, {@link OverlayView} and {@link CropImageView} properly.
 */
@SuppressWarnings("deprecation")
private void processOptions(@NonNull Intent intent) {
    // Bitmap compression options
    String compressionFormatName = intent.getStringExtra(UCrop.Options.EXTRA_COMPRESSION_FORMAT_NAME);
    Bitmap.CompressFormat compressFormat = null;
    if (!TextUtils.isEmpty(compressionFormatName)) {
        compressFormat = Bitmap.CompressFormat.valueOf(compressionFormatName);
    }
    mCompressFormat = (compressFormat == null) ? DEFAULT_COMPRESS_FORMAT : compressFormat;

    mCompressQuality = intent.getIntExtra(UCrop.Options.EXTRA_COMPRESSION_QUALITY, UCropActivity.DEFAULT_COMPRESS_QUALITY);

    // Gestures options
    int[] allowedGestures = intent.getIntArrayExtra(UCrop.Options.EXTRA_ALLOWED_GESTURES);
    if (allowedGestures != null && allowedGestures.length == TABS_COUNT) {
        mAllowedGestures = allowedGestures;
    }

    // Crop image view options
    mGestureCropImageView.setMaxBitmapSize(intent.getIntExtra(UCrop.Options.EXTRA_MAX_BITMAP_SIZE, CropImageView.DEFAULT_MAX_BITMAP_SIZE));
    mGestureCropImageView.setMaxScaleMultiplier(intent.getFloatExtra(UCrop.Options.EXTRA_MAX_SCALE_MULTIPLIER, CropImageView.DEFAULT_MAX_SCALE_MULTIPLIER));
    mGestureCropImageView.setImageToWrapCropBoundsAnimDuration(intent.getIntExtra(UCrop.Options.EXTRA_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION, CropImageView.DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION));


    // Overlay view options
    mOverlayView.setDimmedColor(intent.getIntExtra(UCrop.Options.EXTRA_DIMMED_LAYER_COLOR, getResources().getColor(R.color.ucrop_color_default_dimmed)));
    mOverlayView.setOvalDimmedLayer(intent.getBooleanExtra(UCrop.Options.EXTRA_OVAL_DIMMED_LAYER, OverlayView.DEFAULT_OVAL_DIMMED_LAYER));

    mOverlayView.setShowCropFrame(intent.getBooleanExtra(UCrop.Options.EXTRA_SHOW_CROP_FRAME, OverlayView.DEFAULT_SHOW_CROP_FRAME));
    mOverlayView.setCropFrameColor(intent.getIntExtra(UCrop.Options.EXTRA_CROP_FRAME_COLOR, getResources().getColor(R.color.ucrop_color_default_crop_frame)));
    mOverlayView.setCropFrameStrokeWidth(intent.getIntExtra(UCrop.Options.EXTRA_CROP_FRAME_STROKE_WIDTH, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_frame_stoke_width)));

    mOverlayView.setShowCropGrid(intent.getBooleanExtra(UCrop.Options.EXTRA_SHOW_CROP_GRID, OverlayView.DEFAULT_SHOW_CROP_GRID));
    mOverlayView.setCropGridRowCount(intent.getIntExtra(UCrop.Options.EXTRA_CROP_GRID_ROW_COUNT, OverlayView.DEFAULT_CROP_GRID_ROW_COUNT));
    mOverlayView.setCropGridColumnCount(intent.getIntExtra(UCrop.Options.EXTRA_CROP_GRID_COLUMN_COUNT, OverlayView.DEFAULT_CROP_GRID_COLUMN_COUNT));
    mOverlayView.setCropGridColor(intent.getIntExtra(UCrop.Options.EXTRA_CROP_GRID_COLOR, getResources().getColor(R.color.ucrop_color_default_crop_grid)));
    mOverlayView.setCropGridStrokeWidth(intent.getIntExtra(UCrop.Options.EXTRA_CROP_GRID_STROKE_WIDTH, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)));
}
 
Example 4
Project: RLibrary   File: CropImageView.java   View Source Code Vote up 6 votes
/**
 * 将图片保存在本地
 */
private void saveOutput(Bitmap croppedImage, Bitmap.CompressFormat outputFormat, File saveFile) {
    OutputStream outputStream = null;
    try {
        outputStream = getContext().getContentResolver().openOutputStream(Uri.fromFile(saveFile));
        if (outputStream != null) croppedImage.compress(outputFormat, 90, outputStream);
        Message.obtain(mHandler, SAVE_SUCCESS, saveFile).sendToTarget();
    } catch (IOException ex) {
        ex.printStackTrace();
        Message.obtain(mHandler, SAVE_ERROR, saveFile).sendToTarget();
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    mSaving = false;
    croppedImage.recycle();
}
 
Example 5
Project: android-titanium-imagecropper   File: BitmapCroppingWorkerTask.java   View Source Code Vote up 5 votes
BitmapCroppingWorkerTask(
    CropImageView cropImageView,
    Uri uri,
    float[] cropPoints,
    int degreesRotated,
    int orgWidth,
    int orgHeight,
    boolean fixAspectRatio,
    int aspectRatioX,
    int aspectRatioY,
    int reqWidth,
    int reqHeight,
    boolean flipHorizontally,
    boolean flipVertically,
    CropImageView.RequestSizeOptions options,
    Uri saveUri,
    Bitmap.CompressFormat saveCompressFormat,
    int saveCompressQuality) {

  mCropImageViewReference = new WeakReference<>(cropImageView);
  mContext = cropImageView.getContext();
  mUri = uri;
  mCropPoints = cropPoints;
  mDegreesRotated = degreesRotated;
  mFixAspectRatio = fixAspectRatio;
  mAspectRatioX = aspectRatioX;
  mAspectRatioY = aspectRatioY;
  mOrgWidth = orgWidth;
  mOrgHeight = orgHeight;
  mReqWidth = reqWidth;
  mReqHeight = reqHeight;
  mFlipHorizontally = flipHorizontally;
  mFlipVertically = flipVertically;
  mReqSizeOptions = options;
  mSaveUri = saveUri;
  mSaveCompressFormat = saveCompressFormat;
  mSaveCompressQuality = saveCompressQuality;
  mBitmap = null;
}
 
Example 6
Project: MaterialOCR   File: CropParameters.java   View Source Code Vote up 5 votes
public CropParameters(int maxResultImageSizeX, int maxResultImageSizeY,
                      Bitmap.CompressFormat compressFormat, int compressQuality,
                      String imageInputPath, String imageOutputPath, ExifInfo exifInfo) {
    mMaxResultImageSizeX = maxResultImageSizeX;
    mMaxResultImageSizeY = maxResultImageSizeY;
    mCompressFormat = compressFormat;
    mCompressQuality = compressQuality;
    mImageInputPath = imageInputPath;
    mImageOutputPath = imageOutputPath;
    mExifInfo = exifInfo;
}
 
Example 7
Project: android-titanium-imagecropper   File: BitmapCroppingWorkerTask.java   View Source Code Vote up 5 votes
BitmapCroppingWorkerTask(
    CropImageView cropImageView,
    Bitmap bitmap,
    float[] cropPoints,
    int degreesRotated,
    boolean fixAspectRatio,
    int aspectRatioX,
    int aspectRatioY,
    int reqWidth,
    int reqHeight,
    boolean flipHorizontally,
    boolean flipVertically,
    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;
  mFlipHorizontally = flipHorizontally;
  mFlipVertically = flipVertically;
  mReqSizeOptions = options;
  mSaveUri = saveUri;
  mSaveCompressFormat = saveCompressFormat;
  mSaveCompressQuality = saveCompressQuality;
  mOrgWidth = 0;
  mOrgHeight = 0;
}
 
Example 8
Project: GeekZone   File: ScreenshotUtils.java   View Source Code Vote up 5 votes
public static boolean screenshotToFileWithWallpaperIf(Activity activity, File file,
                                                      Bitmap.CompressFormat compressFormat,
                                                      int quality) {
    if (ThemeUtils.isWallpaperTheme(activity)) {
        return screenshotToFileWithWallpaper(activity, file, compressFormat, quality);
    } else {
        return screenshotToFile(activity, file, compressFormat, quality);
    }
}
 
Example 9
Project: media-picker-android   File: FileUtils.java   View Source Code Vote up 5 votes
public static boolean bitmapToFile(Bitmap bitmap, String path, int quality, Bitmap.CompressFormat format) {
    boolean result = true;
    try {
        OutputStream out = new FileOutputStream(new File(path));
        result = bitmap.compress(format, quality, out);
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
        result = false;
    }

    return result;
}
 
Example 10
Project: media-picker-android   File: MediaPhotoProcessor.java   View Source Code Vote up 5 votes
private Bitmap.CompressFormat getCompressType(PhotoOptions originalPhotoOptions) {
    if (originalPhotoOptions.getType().length() > 0) {
        String type = originalPhotoOptions.getType().toLowerCase();

        if (type.equals("jpg") || type.equals("jpeg")) {
            return Bitmap.CompressFormat.JPEG;
        } else if (type.equals("png")) {
            return Bitmap.CompressFormat.PNG;
        } else if (type.equals("webp")) {
            return Bitmap.CompressFormat.WEBP;
        }
    }
    return Bitmap.CompressFormat.JPEG;
}
 
Example 11
Project: newIPlay   File: ConvertUtils.java   View Source Code Vote up 5 votes
/**
 * bitmap转byteArr
 *
 * @param bitmap bitmap对象
 * @param format 格式
 * @return 字节数组
 */
public static byte[] bitmap2Bytes(Bitmap bitmap, Bitmap.CompressFormat format) {
    if (bitmap == null)
        return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(format, 100, baos);
    return baos.toByteArray();
}
 
Example 12
Project: android-titanium-imagecropper   File: CropImage.java   View Source Code Vote up 4 votes
/**
 * the compression format to use when writting the image.<br>
 * <i>Default: JPEG</i>
 */
public ActivityBuilder setOutputCompressFormat(Bitmap.CompressFormat outputCompressFormat) {
  mOptions.outputCompressFormat = outputCompressFormat;
  return this;
}
 
Example 13
Project: GitHub   File: GlideOptions.java   View Source Code Vote up 4 votes
/**
 * @see RequestOptions#encodeFormatOf(CompressFormat)
 */
@CheckResult
public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) {
  return new GlideOptions().encodeFormat(arg0);
}
 
Example 14
Project: GitHub   File: GlideOptions.java   View Source Code Vote up 4 votes
/**
 * @see RequestOptions#encodeFormatOf(CompressFormat)
 */
@CheckResult
public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) {
  return new GlideOptions().encodeFormat(arg0);
}
 
Example 15
Project: MarsBootProject   File: CropParameters.java   View Source Code Vote up 4 votes
public void setOutputFormat(Bitmap.CompressFormat outputFormat) {
    this.outputFormat = outputFormat;
}
 
Example 16
Project: JD-Test   File: ImageCompressor.java   View Source Code Vote up 4 votes
public Builder setCompressFormat(Bitmap.CompressFormat compressFormat) {
    imageCompressor.compressFormat = compressFormat;
    return this;
}
 
Example 17
Project: HeadlineNews   File: ConvertUtils.java   View Source Code Vote up 3 votes
/**
 * bitmap转byteArr
 *
 * @param bitmap bitmap对象
 * @param format 格式
 * @return 字节数组
 */
public static byte[] bitmap2Bytes(final Bitmap bitmap, final Bitmap.CompressFormat format) {
    if (bitmap == null) return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(format, 100, baos);
    return baos.toByteArray();
}
 
Example 18
Project: Cluttr   File: CropImageView.java   View Source Code Vote up 3 votes
/**
 * Save the cropped image based on the current crop window to the given uri.<br>
 * The result will be invoked to listener set by {@link #setOnCropImageCompleteListener(OnCropImageCompleteListener)}.
 *
 * @param saveUri the Android Uri to save the cropped image to
 * @param saveCompressFormat the compression format to use when writing the image
 * @param saveCompressQuality the quality (if applicable) to use when writing the image (0 - 100)
 * @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, see its documentation
 */
public void saveCroppedImageAsync(Uri saveUri, Bitmap.CompressFormat saveCompressFormat, int saveCompressQuality, int reqWidth, int reqHeight, RequestSizeOptions options) {
    if (mOnCropImageCompleteListener == null) {
        throw new IllegalArgumentException("mOnCropImageCompleteListener is not set");
    }
    startCropWorkerTask(reqWidth, reqHeight, options, saveUri, saveCompressFormat, saveCompressQuality);
}
 
Example 19
Project: Android-Demo_ImageCroper   File: CropImageView.java   View Source Code Vote up 2 votes
/**
 * Save the cropped image based on the current crop window to the given uri.<br>
 * Uses {@link RequestSizeOptions#RESIZE_INSIDE} option.<br>
 * The result will be invoked to listener set by {@link #setOnGetCroppedImageCompleteListener(OnGetCroppedImageCompleteListener)}.
 *
 * @param saveUri the Android Uri to save the cropped image to
 * @param saveCompressFormat the compression format to use when writing the image
 * @param saveCompressQuality the quality (if applicable) to use when writing the image (0 - 100)
 * @param reqWidth the width to resize the cropped image to
 * @param reqHeight the height to resize the cropped image to
 */
public void saveCroppedImageAsync(Uri saveUri, Bitmap.CompressFormat saveCompressFormat, int saveCompressQuality, int reqWidth, int reqHeight) {
    saveCroppedImageAsync(saveUri, saveCompressFormat, saveCompressQuality, reqWidth, reqHeight, RequestSizeOptions.RESIZE_INSIDE);
}
 
Example 20
Project: GitHub   File: ConvertUtils.java   View Source Code Vote up 2 votes
/**
 * drawable转byteArr
 *
 * @param drawable drawable对象
 * @param format   格式
 * @return 字节数组
 */
public static byte[] drawable2Bytes(final Drawable drawable, final Bitmap.CompressFormat format) {
    return drawable == null ? null : bitmap2Bytes(drawable2Bitmap(drawable), format);
}