gpt4 book ai didi

java - 如何在android java中使用PixelCopy API从View中获取位图

转载 作者:行者123 更新时间:2023-12-04 08:13:30 28 4
gpt4 key购买 nike

目前我正在使用 view.getDrawingCache() 现在获取绘图缓存是已弃用

view.setDrawingCacheEnabled(true);
Bitmap bitamp = Bitmap.createBitmap(view.getDrawingCache())
view.setDrawingCacheEnabled(false);
view.getDrawingCache() is deprecated in 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()));
}
无法解决 回电
  • Activity
  • 窗口
  • 经办人

  • 哪个是 super 回调类?

    最佳答案

    查看这篇文章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
    PixelCopy 的 Android 文档 doc

    关于java - 如何在android java中使用PixelCopy API从View中获取位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65828719/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com