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
Android - Navigation View Item Menu Background Color
Android Wear App Not Installing Through Handset
How to Implement a Gcm Hello World for Android Using Android Studio
Problem About SQLite Database, No Such Table
Moving or Copying Data from One Node to Another in Firebase Database
Android Multiple Screen Sizes with Same Density
How to Show Popupwindow at Special Location
Otp (Token) Should Be Automatically Read from the Message
Get Last Inserted Value from SQLite Database Android
Broadcast Receiver Not Working in Android Oreo
Realm with Pre Populated Data into Assets
Extracting Information from a Scanned Gs1-Type Barcode
Display Unity Scene as Sub View in Android Studio
Error Building Player: Commandinvokationfailure: Unable to Convert Classes into Dex Format
Failure [Install_Failed_Update_Incompatible] Even If App Appears to Not Be Installed
Estimating Beacon Proximity/Distance Based on Rssi - Bluetooth Le