Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * This file is part of TexturePoemApp.
 * Created by Matthias Perkonigg, 2015.
 * TexturePoemApp is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *   
 *  TexturePoemApp is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TexturePoemApp.  If not, see <http://www.gnu.org/licenses/>.
 */

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;

import java.io.File;

public class Main {
    /**
     * Gets a bitmap from a path inside the TexturePoemApp-Folder
     * @param path path of the bitmap inside the TexturePoemApp-Folder
     * @return Decoded bitmap 
     */
    public static Bitmap getBitmapFromPath(String path) {
        Bitmap b = null;
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            String galleryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                    .toString();

            File f = new File(galleryPath + "/TexturePoemApp/" + path);
            if (f.exists()) {
                b = BitmapFactory.decodeFile(f.getAbsolutePath());
            }
        }

        return b;
    }
}