I'm trying to take a screenshot of a CardView
that has a shadow (elevation). However, the screenshot comes out without the shadow.
Any ideas?
This is my code:
View v = mView.RootView;
v.DrawingCacheEnabled = true;
Bitmap b = v.DrawingCache;
I'm trying to take a screenshot of a CardView
that has a shadow (elevation). However, the screenshot comes out without the shadow.
Any ideas?
This is my code:
View v = mView.RootView;
v.DrawingCacheEnabled = true;
Bitmap b = v.DrawingCache;
Shadows (Elevation
In API25+) are hardware accelerated and are not available for caching at the view level.
Also if you turn off the hardware acceleration for a View
(actually its parent) than the elevation effect is also disable thus not available for caching...
(aView.Parent as View).SetLayerType(LayerType.Software, null);
A View Cache Capture Example:
Bitmap CaptureView(View view)
{
if (view.IsHardwareAccelerated)
Toast.MakeText(ApplicationContext, "View Is Hardware Accelerated, Effects will not be captured", ToastLength.Long).Show();
view.BuildDrawingCache();
Bitmap bitmap = view.GetDrawingCache(false);
Bitmap bitmapCopy = bitmap.Copy(Bitmap.Config.Argb8888, false);
view.DestroyDrawingCache();
return bitmapCopy;
}