trivial: creating an activity with only a large bitmap

Problems with Canvas, OpenGL, etc...

trivial: creating an activity with only a large bitmap

Postby flok » Fri Sep 03, 2010 11:54 am

Hi,

I'm trying something simple but failing horribly somehow.
I'm trying to create an app that only shows a bitmap with the size of the screen and then enabling me to color pixels on it. In Java that would be creating a BufferedImage, retrieving the Graphics-object-version and plotting away. Now what I found (thanks Google!) I should do something like the following but it doesn't work: I always get a null-pointer from the "ImageView jpgView = (ImageView)findViewById(R.id.blaimg);":
Code: Select all
public class Test extends Activity {
...
    // called from 'onOptionsItemSelected'
    public void draw() {
        try {
           // get pointer to image-object
           ImageView jpgView = (ImageView)findViewById(R.id.blaimg);
         // retrieve image from the internet
           BitmapFactory.Options options = new BitmapFactory.Options();
           InputStream is = null;
               URL url = new URL("http://keetweej.vanheusden.com/~folkert/test.jpg");
               HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoInput(true);
                connection.connect();
                InputStream input = connection.getInputStream();
                Bitmap myBitmap = BitmapFactory.decodeStream(input);

            // debug-output & display image
               TextView mOutputWindow= (TextView) findViewById(R.id.bla);
               mOutputWindow.append("img: " + myBitmap + "\n");
               mOutputWindow.append("jpg: " + jpgView + "\n");
         jpgView.setImageBitmap(myBitmap );
        }
        catch(Exception e) {
        }
    }
}


The layout xml:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView android:text="bla" android:id="@+id/bla" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <ImageView id="@+id/blaimg"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>


What am I doing wrong?
flok
Freshman
Freshman
 
Posts: 3
Joined: Fri Sep 03, 2010 11:42 am
Location: Gouda, the Netherlands

Top

Re: trivial: creating an activity with only a large bitmap

Postby flok » Fri Sep 03, 2010 4:53 pm

Found it:
<ImageView id="@+id/blaimg"
should've been:
<ImageView android:id="@+id/blaimg"
flok
Freshman
Freshman
 
Posts: 3
Joined: Fri Sep 03, 2010 11:42 am
Location: Gouda, the Netherlands

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest