Android 2.1 View's Getdrawingcache() Method Always Returns Null

Call to `getDrawingCache` returns null when scroll is enabled

I solved it. Created a bitmap of view size and drew the view into it.

TableLayout page = (TableLayout) findViewById(R.id.page);
Bitmap pageBmp = Bitmap.createBitmap(page.getWidth(), page.getHeight(),
Config.ARGB_8888);
Canvas canvas = new Canvas(pageBmp);
page.draw(canvas);

Used the pageBmp bitmap..

getDrawingCache() always returning null

Try calling buildDrawingCache() before getDrawingCache()

EDIT:
Call getDrawingCache(), after the page have loaded, instead of onCreate

Android ImageView drawing cache is null even after layout

I got rid of the ViewTreeObserver and did my cropping onLayout and now everything seems to be working ok.

protected void onLayout (boolean changed, int left, int top, int right, int bottom){
super.onLayout(changed, left, top, right, bottom);

crop();
}

Android get full View as Bitmap

buildDrawingCache should not have your view if it is bigger than the screen as the visible portion of the view is only drawn and the cache holds only what is drawn.

You may try this method. Here a bitmap is passed to the view, so that the view is drawon to the bitmap.
http://www.brighthub.com/mobile/google-android/articles/30676.aspx

Android drawing cache

There's a hard limit on drawing cache size, available via the ViewConfiguration class.. My view is larger than allowed for caching.

FYI, the sources of the View class are available via the SDK Manager for some (not all) Android versions.

NullpointerException when trying to save the current Android app view as image

Try it -

public static Bitmap convertViewToBitmap(View view) {
Bitmap result = null;

try {
result = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.RGB_565);
view.draw(new Canvas(result));
}catch(Exception e) {}
return result;
}

Null Pointer Exception when trying to get image from ImageView

Its better if you directly pass the Bitmap rather than imgHolder.getDrawableCache(), it should work,

BitmapDrawable drawable = (BitmapDrawable) imgHolder.getDrawable();
Bitmap bitmap = drawable.getBitmap();

i = new Intent(v.getContext(), ViewActivity.class);
//Add contact to database
dbAdapter.addContact(nameBox.getText().toString(), numberBox.getText().toString(), emailBox.getText().toString(), bitmap);
startActivity(i);


Related Topics



Leave a reply



Submit