Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;

import android.os.Environment;

import android.util.Log;

public class Main {
    private static final String TAG = "HelperMethods";
    private static int picCompression = 100;
    private static String storageTarget = Environment.getExternalStorageDirectory().getAbsoluteFile() + "";

    /**
     * From original Android Camera App
     * See: http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=blob;f=src/com/android/camera/ImageManager.java;h=76a6d1dffdcfb91f2c55032ce14f7cd9ecf7962c;hb=HEAD
     * @param imageData
     * @param quality
     * @param filename
     * @return
     */
    public static boolean StoreByteImage(byte[] imageData, int quality, String filename) {
        String directory = storageTarget + "/FreqCap";
        Bitmap source = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);

        OutputStream outputStream = null;
        String filePath = directory + "/" + filename;
        try {
            File dir = new File(directory);
            if (!dir.exists())
                dir.mkdirs();
            File file = new File(directory, filename);
            outputStream = new FileOutputStream(file);
            if (source != null) {
                source.compress(CompressFormat.JPEG, picCompression, outputStream);
            } else {
                outputStream.write(imageData);
                // degree[0] = getExifOrientation(filePath);
            }
            //         outputStream.flush();
            //         outputStream.close();
            Log.e(TAG, file.getAbsolutePath());
        } catch (FileNotFoundException ex) {
            Log.w(TAG, ex);
            return false;
        } catch (IOException ex) {
            Log.w(TAG, ex);
            return false;
        } finally {
            closeSilently(outputStream);
        }
        return true;
    }

    public static void closeSilently(Closeable c) {
        if (c == null)
            return;
        try {
            c.close();
        } catch (Throwable t) {
            // do nothing
        }
    }
}