在方法内部屏幕捕获的onCreate不是Android平台 [英] Screen capture inside the method onCreate not working in android

查看:90
本文介绍了在方法内部屏幕捕获的onCreate不是Android平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用程序的工作,我想捕捉当前活动的屏幕在Overrided方法的onCreate()。当我写了code捕捉画面Overrided方法的onCreate()内的位图返回null。但是,当我在同一个活动调用相同的code在点击一个按钮位图返回正确的值。请纠正我的code。通过位图我ocCreate返回()方法本身。

我的code是:

 查看V1 = findViewById(R.id.print previewBaseScrollView);
v1.setDrawingCacheEnabled(真);
位图BMV = v1.getDrawingCache();


解决方案

 查看printlayout = findViewById(R.id.print previewBaseRelativeLayout);
        printlayout.setDrawingCacheEnabled(真);        printlayout.measure(printlayout.getMeasuredWidth(),
                printlayout.getMeasuredHeight());         printlayout.layout(0,0,700 1755);        Log.e(宽,+ printlayout.getMeasuredWidth());
        Log.e(HIGHT,+ printlayout.getMeasuredHeight());        printlayout.buildDrawingCache(真);        位图= Bitmap.createBitmap(printlayout.getDrawingCache());
        printlayout.setDrawingCacheEnabled(假); //明确绘图缓存

I am working in an android application and I want to capture the screen of current activity in the Overrided method onCreate(). The bitmap returns null when I wrote the code for capturing screen inside the Overrided method onCreate(). But when I call the same code in a button click in the same activity the bitmap returns the correct value. Please correct my code to return by bitmap in my ocCreate() method itself.

My code is :

View v1 = findViewById(R.id.printpreviewBaseScrollView);
v1.setDrawingCacheEnabled(true);
Bitmap bmv = v1.getDrawingCache();

解决方案

View printlayout = findViewById(R.id.printpreviewBaseRelativeLayout);
        printlayout.setDrawingCacheEnabled(true);

        printlayout.measure(printlayout.getMeasuredWidth(),
                printlayout.getMeasuredHeight());

         printlayout.layout(0, 0, 700, 1755);



        Log.e("width", "" + printlayout.getMeasuredWidth());
        Log.e("hight", "" + printlayout.getMeasuredHeight());

        printlayout.buildDrawingCache(true);

        bitmap = Bitmap.createBitmap(printlayout.getDrawingCache());
        printlayout.setDrawingCacheEnabled(false); // clear drawing cache

这篇关于在方法内部屏幕捕获的onCreate不是Android平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆