当前我正在使用view.getDrawingCache()现在不赞成使用图形缓存
view.setDrawingCacheEnabled(true);
Bitmap bitamp = Bitmap.createBitmap(view.getDrawingCache())
view.setDrawingCacheEnabled(false);
view.getDrawingCache()在Android API 28中已弃用
Java代码中的解决方案出现错误 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()));
}
无法解决回调
哪个是回调的晚餐类?
检查本文OnPixelCopyFinishedListener
PixalCopy.java文件中提供了CallBack接口
/**
* 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);
}
适用于PixelCopy文档的Android文档
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句