作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前我正在使用 view.getDrawingCache() 现在获取绘图缓存是已弃用
view.setDrawingCacheEnabled(true);
Bitmap bitamp = Bitmap.createBitmap(view.getDrawingCache())
view.setDrawingCacheEnabled(false);
view.getDrawingCache() is deprecated in Android API 28
Callback
@RequiresApi(api = Build.VERSION_CODES.O)
public static void getBitmapFormView(View view, Activity activity, Callback callback) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
int[] locations = new int[2];
view.getLocationInWindow(locations);
Rect rect = new Rect(locations[0], locations[1], locations[0] + view.getWidth(), locations[1] + view.getHeight());
PixelCopy.request(activity.getWindow(), rect, bitmap, copyResult -> {
if (copyResult == PixelCopy.SUCCESS) {
callback.onResult(bitmap);
}
}, new Handler(Looper.getMainLooper()));
}
无法解决
回电
最佳答案
查看这篇文章CallBack接口(interface)是OnPixelCopyFinishedListener
在 PixalCopy.java 文件中可用
/**
* Listener for observing the completion of a PixelCopy request.
*/
public interface OnPixelCopyFinishedListener {
/**
* Callback for when a pixel copy request has completed. This will be called
* regardless of whether the copy succeeded or failed.
*
* @param copyResult Contains the resulting status of the copy request.
* This will either be {@link PixelCopy#SUCCESS} or one of the
* <code>PixelCopy.ERROR_*</code> values.
*/
void onPixelCopyFinished(@CopyResultStatus int copyResult);
}
https://medium.com/@shiveshmehta09/taking-screenshot-programmatically-using-pixelcopy-api-83c84643b02a
关于java - 如何在android java中使用PixelCopy API从View中获取位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65828719/
我是一名优秀的程序员,十分优秀!