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 java.io.IOException;

import android.graphics.Bitmap;

import android.util.Log;

public class Main {
    public static byte[] bitmapDecode(Bitmap bmp) throws IOException {
        if (bmp != null && bmp.isRecycled())
            return null;
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        if (bmp == null) {
            // Resources res=context.getResources();
            // bmp=BitmapFactory.decodeResource(res,R.drawable.icon);
            // System.out.println("bitmapDecode@CDBPersistent----exception bmp is null,use default book");
            return null;
        }

        bmp.compress(Bitmap.CompressFormat.PNG, 10, out);

        byte[] array = null;
        try {
            array = out.toByteArray();
        } catch (OutOfMemoryError e) {
            Log.e("arrayoom", "", e);
        }
        return array;
    }
}