Ir a la documentación de este archivo.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00026 package com.googlecode.leptonica.android;
00027
00028 import android.graphics.Bitmap;
00029 import android.graphics.Bitmap.CompressFormat;
00030
00031 import java.io.ByteArrayOutputStream;
00032 import java.io.IOException;
00033
00038 public class JpegIO {
00039 static {
00040 System.loadLibrary("lept");
00041 }
00042
00044 public static final int DEFAULT_QUALITY = 85;
00045
00050 public static final boolean DEFAULT_PROGRESSIVE = false;
00051
00059 public static byte[] compressToJpeg(Pix pixs) {
00060 return compressToJpeg(pixs, DEFAULT_QUALITY, DEFAULT_PROGRESSIVE);
00061 }
00062
00074 public static byte[] compressToJpeg(Pix pixs, int quality,
00075 boolean progressive) {
00076 if (pixs == null)
00077 throw new IllegalArgumentException("Source pix must be non-null");
00078 if (quality < 0 || quality > 100)
00079 throw new IllegalArgumentException(
00080 "Quality must be between 0 and 100 (inclusive)");
00081
00082 final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
00083 final Bitmap bmp = WriteFile.writeBitmap(pixs);
00084 bmp.compress(CompressFormat.JPEG, quality, byteStream);
00085 bmp.recycle();
00086
00087 final byte[] encodedData = byteStream.toByteArray();
00088
00089 try {
00090 byteStream.close();
00091 } catch (IOException e) {
00092 e.printStackTrace();
00093 }
00094
00095 return encodedData;
00096 }
00097
00098
00099
00100
00101
00102 private static native byte[] nativeCompressToJpeg(int nativePix,
00103 int quality, boolean progressive);
00104 }