Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 CanvasDrawUtils.java
 Copyright (c) 2015 NTT DOCOMO,INC.
 Released under the MIT license
 http://opensource.org/licenses/mit-license.php
 */

import android.graphics.BitmapFactory;

public class Main {
    /**
     * Defined a size of size.
     */
    private static final int MAX_SIZE = 2048;

    /**
     * Checks whether data is valid.
     *
     * @param data image data
     * @return true if data is valid, false otherwise
     */
    public static boolean checkBitmap(byte[] data) {
        if (data != null) {
            try {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeByteArray(data, 0, data.length, options);
                if (options.outWidth > MAX_SIZE || options.outHeight > MAX_SIZE) {
                    return false;
                } else {
                    return options.outWidth > 0 && options.outHeight > 0;
                }
            } catch (Throwable t) {
                // format error if an error has occurred
                return false;
            }
        }
        return false;
    }
}