OpenBitmapsActivity.java

Source code used to produce the problem - Corey Beres, 2011-08-06 10:14 am

Download (1.5 kB)

 
1
package com.corey.openbitmaps;
2
3
import java.io.File;
4
5
import org.opencv.android;
6
import org.opencv.core.Mat;
7
8
import android.app.Activity;
9
import android.graphics.Bitmap;
10
import android.graphics.BitmapFactory;
11
import android.os.Bundle;
12
import android.os.Environment;
13
import android.util.Log;
14
15
public class OpenBitmapsActivity extends Activity {
16
        
17
        private final String TAG = "OpenBitmaps";
18
        
19
        private Mat mat;
20
        
21
    /** Called when the activity is first created. */
22
    @Override
23
    public void onCreate(Bundle savedInstanceState) {
24
        super.onCreate(savedInstanceState);
25
        setContentView(R.layout.main);
26
        
27
        if (isExternalStorageReadable()) {
28
                String filename = "/mnt/sdcard/Images/windsor_chair_0002.jpg";
29
                        Bitmap bmp = BitmapFactory.decodeFile(filename);
30
                        mat = android.BitmapToMat(bmp);
31
        
32
                        Log.d(TAG, filename + ": exists=" + new File(filename).exists());
33
                        Log.d(TAG, filename + ": " + bmp.getHeight() + "x" + bmp.getWidth());
34
                        Log.d(TAG, filename + ": " + mat.size().height + "x" + mat.size().width);
35
        }
36
    }
37
        
38
        private boolean isExternalStorageReadable() {
39
            boolean mExternalStorageAvailable = false;
40
            String state = Environment.getExternalStorageState();
41
42
            if (Environment.MEDIA_MOUNTED.equals(state)) {
43
                // We can read and write the media
44
                mExternalStorageAvailable = true;
45
            } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
46
                // We can only read the media
47
                mExternalStorageAvailable = true;
48
            }
49
            
50
            return mExternalStorageAvailable;
51
    }
52
}