Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

import java.io.ByteArrayOutputStream;

public class Main {
    /**
     * Bitmap into compressed jpeg
     *
     * @param image the Bitmap
     * @param quality quality of compression
     * @return byte array of jpeg
     */
    public static byte[] bitmapToJpg(final Bitmap image, final int quality) {
        if (image == null)
            return null;

        ByteArrayOutputStream ba = new ByteArrayOutputStream();

        if (image.compress(CompressFormat.JPEG, quality, ba))
            return ba.toByteArray();
        else
            return null;
    }
}