Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;

public class Main {
    /**
     * Bitmap -> byte
     * 
     * @param bitmap
     * @return
     */
    public static byte[] bitmapToByte(Bitmap bitmap) {
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            bitmap.recycle();
            bitmap = null;
            byte[] array = out.toByteArray();
            return array;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}