RGB von Bitmap

fm it

Mitglied
Hallo,
Ich versuche gerade von einem Foto aus meinem Dateiexplorer (Samsung Android) die RGB Werte auszulesen im internet hab ich einen kleinen vorgefertigten Code gefunden ich hab ihn eingefügt jede Fehlermeldung behoben trotzdem funktionierter nicht wisst ihr vielleicht was ich falsch mache ?
Java:
package com.example.loadbitmap;

import java.io.FileNotFoundException;

import android.os.Bundle;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.Menu;

public class MainActivity extends Activity {
	Bitmap bmp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
    bmp = BitmapFactory.decodeFile("photo.jpg");
	System.out.println("Bild geladen");
	
	int picw = 0;
	int[] pix = null;
	int pich = 0;
	bmp.getPixels(pix, 0, picw, 0, 0, picw, pich);

    for (int i = 0; i < pix.length; i++) {
        int r = (pix[i]) >> 16 & 0xff;
        int g = (pix[i]) >> 8 & 0xff;
        int b = (pix[i]) & 0xff;
        System.out.println("R:"+ r + "G :" + g +"B:"+ b );
    }
	
    }}

Danke :)
 

fm it

Mitglied
Code:
10-18 15:32:00.929: E/AndroidRuntime(12456): FATAL EXCEPTION: main
10-18 15:32:00.929: E/AndroidRuntime(12456): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.loadbitmap/com.example.loadbitmap.MainActivity}: java.lang.NullPointerException
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.os.Handler.dispatchMessage(Handler.java:99)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.os.Looper.loop(Looper.java:130)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.app.ActivityThread.main(ActivityThread.java:3687)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at java.lang.reflect.Method.invoke(Method.java:507)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at dalvik.system.NativeStart.main(Native Method)
10-18 15:32:00.929: E/AndroidRuntime(12456): Caused by: java.lang.NullPointerException
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at com.example.loadbitmap.MainActivity.onCreate(MainActivity.java:22)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
10-18 15:32:00.929: E/AndroidRuntime(12456): 	... 11 more