Compress the bitmap to the byte array as the specified format and quality.
@param bitmap to compress.
@param format the format.
@param quality the quality of the compressed bitmap.
@return the compressed bitmap byte array.
178161
public static byte[] toByteArray(Bitmap bitmap, Bitmap.CompressFormat format, int quality) {
        ByteArrayOutputStream out = null;
        try {
            out = new ByteArrayOutputStream();
            bitmap.compress(format, quality, out);
            return out.toByteArray();
        } finally {
            CloseableUtils.close(out);
        }
    }
199314
public java.awt.Graphics2D createGraphicsShapes(float width, float height, boolean convertImagesToJPEG, float quality) {
        return new PdfGraphics2D(this, width, height, null, true, convertImagesToJPEG, quality);
    }
1163394
public final byte[] compress(byte[] in) {
    switch (this.compressMode) {
      case GZIP:
        return gzipCompress(in);
      case ZIP:
        return zipCompress(in);
      default:
        return gzipCompress(in);
    }

  }
277919
public static Bitmap grayToBitmap( GrayU8 input , Bitmap.Config config ) {
		Bitmap output = Bitmap.createBitmap(input.width, input.height, config);
		
		grayToBitmap(input,output,null);
		
		return output;
	}
779088
public Bitmap drawableToBitmap(Drawable drawable) {
		if (drawable == null)   // Don't do anything without a proper drawable
			return null;
		else if (drawable instanceof BitmapDrawable) {  // Use the getBitmap() method instead if BitmapDrawable
			Log.i(TAG, "Bitmap drawable!");
			return ((BitmapDrawable) drawable).getBitmap();
		}

		int intrinsicWidth = drawable.getIntrinsicWidth();
		int intrinsicHeight = drawable.getIntrinsicHeight();

		if (!(intrinsicWidth > 0 && intrinsicHeight > 0))
			return null;

		try {
			// Create Bitmap object out of the drawable
			Bitmap bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888);
			Canvas canvas = new Canvas(bitmap);
			drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
			drawable.draw(canvas);
			return bitmap;
		} catch (OutOfMemoryError e) {
			// Simply return null of failed bitmap creations
			Log.e(TAG, "Encountered OutOfMemoryError while generating bitmap!");
			return null;
		}
	}
691442
@Override
	public final Bitmap get(String key) {
		if (key == null) {
			throw new NullPointerException("key == null");
		}

		synchronized (this) {
			return map.get(key);
		}
	}
1218885
public static void saveJpeg(Bitmap src, String fileName, int quality) throws ImageSaveException {
        save(src, fileName, Bitmap.CompressFormat.JPEG, quality);
    }
352749
private static void save(Bitmap src, String fileName, Bitmap.CompressFormat format, int quality) throws ImageSaveException {
        FileOutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(fileName);
            src.compress(format, quality, outputStream);
            outputStream.close();
        } catch (IOException e) {
            throw new ImageSaveException(e);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
404856
public static void saveLq(Bitmap src, String fileName) throws ImageSaveException {
        saveJpeg(src, fileName, JPEG_QUALITY_LOW);
    }
1267597
public ImageHandlerBuilder reduceQuality(float qualityPercent) {
         ImageWriter imageWriter = ImageIO.getImageWritersByFormatName(fn.extension()).next();
         if (imageWriter != null) {
             ImageWriteParam writeParam = imageWriter.getDefaultWriteParam();
             writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
             writeParam.setCompressionQuality(qualityPercent);

             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             imageWriter.setOutput(new MemoryCacheImageOutputStream(baos));
             try {
                 imageWriter.write(null, new IIOImage(image, null, null), writeParam);
                 imageWriter.dispose();
             } catch (IOException e) {
                 throw new ControllerException(e);
             }
             
             try {
                BufferedImage lowImage = ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
                image.flush();
                image = lowImage;
            } catch (IOException e) {
                throw new ControllerException(e);
            }
         }
         return this;
     }
1068858
public static int byteSizeOf(Bitmap bitmap) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            return bitmap.getAllocationByteCount();
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
            return bitmap.getByteCount();
        } else {
            return bitmap.getRowBytes() * bitmap.getHeight();
        }
    }
793030
public static Map formatMap(Map conditionMap) {
        Map formattedMap = new HashMap();
        formattedMap.putAll(conditionMap);
        forSpecialValue(formattedMap);
        return formattedMap;
    }
286649
public static FileTransformer fileTransformer(Format format) {
        switch (format) {
            case MATLAB_SPARSE:
                return new MatlabSparseFileTransformer();
            case SVDLIBC_SPARSE_TEXT:
                return new SvdlibcSparseTextFileTransformer();
            case SVDLIBC_DENSE_TEXT:
                return new SvdlibcDenseTextFileTransformer();
            case SVDLIBC_SPARSE_BINARY:
                return new SvdlibcSparseBinaryFileTransformer();
            case SVDLIBC_DENSE_BINARY:
                return new SvdlibcDenseBinaryFileTransformer();
            default:
                throw new UnsupportedOperationException(
                        "Transforming format " + format + " is currently " +
                        "not implemented.  Please email " +
                        "s-space-research-dev@googlegroups.com to have this " +
                        "implemented.");
        }
    }
498213
private static BitmapFactory.Options getDecodeOptionsForStream(
      EncodedImage encodedImage, Bitmap.Config bitmapConfig) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    // Sample size should ONLY be different than 1 when downsampling is enabled in the pipeline
    options.inSampleSize = encodedImage.getSampleSize();
    options.inJustDecodeBounds = true;
    // fill outWidth and outHeight
    BitmapFactory.decodeStream(encodedImage.getInputStream(), null, options);
    if (options.outWidth == -1 || options.outHeight == -1) {
      throw new IllegalArgumentException();
    }

    options.inJustDecodeBounds = false;
    options.inDither = true;
    options.inPreferredConfig = bitmapConfig;
    options.inMutable = true;

    return options;
  }
564007
public static BufferedImage compression(BufferedImage src, int widthScale, int heightScale) {
        int oldWidth = src.getWidth();
        int oldHeight = src.getHeight();
        int width = oldWidth / widthScale + ((oldWidth % widthScale) > 0 ? 1 : 0);
        int height = oldHeight / heightScale + ((oldHeight % heightScale) > 0 ? 1 : 0);

        BufferedImage dest = new BufferedImage(width, height, src.getType());

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                int rgb = src.getRGB(x * widthScale, y * heightScale);
                dest.setRGB(x, y, rgb);
            }
        }

        return dest;
    }
255702
public void saveAsJPEG(File file, int width, int height, float quality) throws IOException, TranscoderException {
    JPEGTranscoder t = new JPEGTranscoder();
    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(width));
    t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new Float(height));
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(quality));
    transcode(file, t);
  }
949654
public static Bitmap getBitmapBySize(String path, int width, int height) {
        BitmapFactory.Options option = new BitmapFactory.Options();
        option.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(path, option);
        option.inSampleSize = computeSampleSize(option, -1, width * height);

        option.inJustDecodeBounds = false;
        Bitmap bitmap = null;
        try {
            bitmap = BitmapFactory.decodeFile(path, option);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }