android 4.4 sdk截图和jni截图实现

首先找到 系统截图Service的源码
public class TakeScreenshotService extends Service
关于怎么获得系统服务见笔记:

        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    final Messenger callback = msg.replyTo;
                    if (mScreenshot == null) {
                        mScreenshot = new GlobalScreenshot(TakeScreenshotService.this);
                    }
                    mScreenshot.takeScreenshot(new Runnable() {
                        @Override public void run() {
                            Message reply = Message.obtain(null, 1);
                            try {
                                callback.send(reply);
                            } catch (RemoteException e) {
                            }
                        }
                    }, msg.arg1 > 0, msg.arg2 > 0);
            }





in GlobalScreenshot.java

android 4.4以下:
    void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
        // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
        // only in the natural orientation of the device :!)
//.....
        // Take the screenshot
        mScreenBitmap = Surface.screenshot((int) dims[0], (int) dims[1]);

android4.4:


    void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) {
        // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
        // only in the natural orientation of the device :!)
...
        // Take the screenshot
        mScreenBitmap = SurfaceControl.screenshot((int) dims[0], (int) dims[1]);


SurfaceControl.screenshot((int) dims[0], (int) dims[1]);是隐藏API
怎么调用见:

如果没有源码可以上



------------
如何在jni层实现截图?
参考SurfaceControl源码


        bool get_sceenrgb(int width,int height){
            sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(  
                ISurfaceComposer::eDisplayIdMain)); 
            mScreenshot.update(dtoken, width, height);
            src_32 = (uint32_t *)mScreenshot.getPixels();
            size = (mScreenshot.getSize());


            //获取屏幕的宽高等信息
            status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
            printf("w=%d,h=%d,xdpi=%f,ydpi=%f,fps=%f,ds=%f \n",
                dinfo.w, dinfo.h, dinfo.xdpi, dinfo.ydpi, dinfo.fps, dinfo.density);
            return true;
        }

由于我只需要它的像素信息.所以没有保存为图片....完整的实现应该构造一个 SkBitmap对象保存
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值