Tesseract-android-tools  1.0
 Todo Clases Namespaces Archivos Funciones Variables
JpegIO.java
Ir a la documentación de este archivo.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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         // * NATIVE CODE *
00100         // ***************
00101 
00102         private static native byte[] nativeCompressToJpeg(int nativePix,
00103                         int quality, boolean progressive);
00104 }
 Todo Clases Namespaces Archivos Funciones Variables