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.BitmapFactory;

public class Main {
    private static final int ZEN_IMAGE_WIDTH = 480;

    public static Bitmap decodeByteArray(byte[] data) {
        try {
            if (data == null) {
                return null;
            }
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeByteArray(data, 0, data.length, options);
            options.inJustDecodeBounds = false;
            int be = (int) (options.outWidth / (float) ZEN_IMAGE_WIDTH);

            if (be <= 0) {
                be = 1;
            }

            options.inSampleSize = be;
            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
            return bitmap;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}