Android Open Source - scanNedit Jpeg I O






From Project

Back to project page scanNedit.

License

The source code is released under:

MIT License

If you think the Android project scanNedit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2011 Google Inc.//  w  w  w .  j a  va  2s  .  c om
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.googlecode.leptonica.android;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * JPEG input and output methods.
 *
 * @author alanv@google.com (Alan Viverette)
 */
public class JpegIO {
    static {
        System.loadLibrary("lept");
    }

    /** Default quality is 85%, which is reasonably good. */
    public static final int DEFAULT_QUALITY = 85;

    /** Progressive encoding is disabled by default to increase compatibility. */
    public static final boolean DEFAULT_PROGRESSIVE = false;

    /**
     * Returns a compressed JPEG byte representation of this Pix using default
     * parameters.
     *
     * @param pixs
     * @return a compressed JPEG byte array representation of the Pix
     */
    public static byte[] compressToJpeg(Pix pixs) {
        return compressToJpeg(pixs, DEFAULT_QUALITY, DEFAULT_PROGRESSIVE);
    }

    /**
     * Returns a compressed JPEG byte representation of this Pix.
     *
     * @param pixs A source pix image.
     * @param quality The quality of the compressed image. Valid range is 0-100.
     * @param progressive Whether to use progressive compression.
     * @return a compressed JPEG byte array representation of the Pix
     */
    public static byte[] compressToJpeg(Pix pixs, int quality, boolean progressive) {
        if (pixs == null)
            throw new IllegalArgumentException("Source pix must be non-null");
        if (quality < 0 || quality > 100)
            throw new IllegalArgumentException("Quality must be between 0 and 100 (inclusive)");

        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        final Bitmap bmp = WriteFile.writeBitmap(pixs);
        bmp.compress(CompressFormat.JPEG, quality, byteStream);
        bmp.recycle();

        final byte[] encodedData = byteStream.toByteArray();

        try {
            byteStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return encodedData;
    }

    // ***************
    // * NATIVE CODE *
    // ***************

    private static native byte[] nativeCompressToJpeg(
            int nativePix, int quality, boolean progressive);
}




Java Source Code List

com.googlecode.leptonica.android.AdaptiveMap.java
com.googlecode.leptonica.android.Binarize.java
com.googlecode.leptonica.android.Box.java
com.googlecode.leptonica.android.Constants.java
com.googlecode.leptonica.android.Convert.java
com.googlecode.leptonica.android.Enhance.java
com.googlecode.leptonica.android.JpegIO.java
com.googlecode.leptonica.android.Pix.java
com.googlecode.leptonica.android.Pixa.java
com.googlecode.leptonica.android.ReadFile.java
com.googlecode.leptonica.android.Rotate.java
com.googlecode.leptonica.android.Scale.java
com.googlecode.leptonica.android.Skew.java
com.googlecode.leptonica.android.WriteFile.java
com.googlecode.tesseract.android.TessBaseAPI.java
com.markupartist.android.widget.ActionBar.java
com.markupartist.android.widget.ActionBar_three.java
com.markupartist.android.widget.ActionBar_two.java
com.markupartist.android.widget.ScrollingTextView.java
com.me.android.scanNedit.CameraActivity.java
com.me.android.scanNedit.CropOptionAdapter.java
com.me.android.scanNedit.CropOption.java
com.me.android.scanNedit.FileCache.java
com.me.android.scanNedit.GalleryActivity.java
com.me.android.scanNedit.HelpActivity.java
com.me.android.scanNedit.ImageLoader.java
com.me.android.scanNedit.LazyAdapter.java
com.me.android.scanNedit.MemoryCache.java
com.me.android.scanNedit.Picture.java
com.me.android.scanNedit.SampleActivity.java
com.me.android.scanNedit.StartActivity.java
com.me.android.scanNedit.TessBaseAPITest.java
com.me.android.scanNedit.Utils.java
com.me.android.scanNedit.XMLParser.java