简体   繁体   English

带阴影视图的 Android 屏幕截图

[英]Android screenshot of view with shadow

I'm trying to take a screenshot of a CardView that has a shadow (elevation).我正在尝试CardView具有阴影(高程)的CardView的屏幕截图。 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.阴影(API25+ 中的Elevation )是硬件加速的,不可用于视图级别的缓存。

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...此外,如果您关闭View (实际上是其父View )的硬件加速,则高程效果也会被禁用,因此无法用于缓存...

(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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM