• <i id='utRKZ'><tr id='utRKZ'><dt id='utRKZ'><q id='utRKZ'><span id='utRKZ'><b id='utRKZ'><form id='utRKZ'><ins id='utRKZ'></ins><ul id='utRKZ'></ul><sub id='utRKZ'></sub></form><legend id='utRKZ'></legend><bdo id='utRKZ'><pre id='utRKZ'><center id='utRKZ'></center></pre></bdo></b><th id='utRKZ'></th></span></q></dt></tr></i><div id='utRKZ'><tfoot id='utRKZ'></tfoot><dl id='utRKZ'><fieldset id='utRKZ'></fieldset></dl></div>

    <legend id='utRKZ'><style id='utRKZ'><dir id='utRKZ'><q id='utRKZ'></q></dir></style></legend>
    1. <tfoot id='utRKZ'></tfoot>

        <bdo id='utRKZ'></bdo><ul id='utRKZ'></ul>
    2. <small id='utRKZ'></small><noframes id='utRKZ'>

        从 ios 表面创建图像并保存

        时间:2023-05-31
          <tbody id='zmjxm'></tbody>
        <tfoot id='zmjxm'></tfoot>
      1. <i id='zmjxm'><tr id='zmjxm'><dt id='zmjxm'><q id='zmjxm'><span id='zmjxm'><b id='zmjxm'><form id='zmjxm'><ins id='zmjxm'></ins><ul id='zmjxm'></ul><sub id='zmjxm'></sub></form><legend id='zmjxm'></legend><bdo id='zmjxm'><pre id='zmjxm'><center id='zmjxm'></center></pre></bdo></b><th id='zmjxm'></th></span></q></dt></tr></i><div id='zmjxm'><tfoot id='zmjxm'></tfoot><dl id='zmjxm'><fieldset id='zmjxm'></fieldset></dl></div>

                <bdo id='zmjxm'></bdo><ul id='zmjxm'></ul>
              • <legend id='zmjxm'><style id='zmjxm'><dir id='zmjxm'><q id='zmjxm'></q></dir></style></legend>

                1. <small id='zmjxm'></small><noframes id='zmjxm'>

                  本文介绍了从 ios 表面创建图像并保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..


                  我正在尝试获取与 ios 设备主屏幕关联的表面,从中创建图像并保存.这与这个问题有关 - 从 iOS 应用程序截屏 - 模拟显示记录器(内部查询).
                  代码如下:


                  I am trying to acquire the surface associated with the main screen of the ios device, create an image out of it and save it. This is in relevance to this question - Taking Screenshots from iOS app - emulating Display recorder (query on the internals).
                  The code is as follows:

                      IOMobileFramebufferConnection connect;
                      kern_return_t result;
                  
                      io_service_t framebufferService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleH1CLCD"));
                      if(!framebufferService)
                          framebufferService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleM2CLCD"));
                      if(!framebufferService)
                          framebufferService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleCLCD"));
                  
                      result = IOMobileFramebufferOpen(framebufferService, mach_task_self(), 0, &connect);
                  
                      result = IOMobileFramebufferGetLayerDefaultSurface(connect, 0, &screenSurface);
                  
                      uint32_t aseed;
                      IOSurfaceLock(screenSurface, kIOSurfaceLockReadOnly, &aseed);
                      uint32_t width = IOSurfaceGetWidth(screenSurface);
                      uint32_t height = IOSurfaceGetHeight(screenSurface);
                  
                      CFMutableDictionaryRef dict;
                      int pitch = width*4, size = 4*width*height;
                      int bPE=4;
                      char pixelFormat[4] = {'A','R','G','B'};
                      dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
                      CFDictionarySetValue(dict, kIOSurfaceIsGlobal, kCFBooleanTrue);
                      CFDictionarySetValue(dict, kIOSurfaceBytesPerRow, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pitch));
                      CFDictionarySetValue(dict, kIOSurfaceBytesPerElement, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bPE));
                      CFDictionarySetValue(dict, kIOSurfaceWidth, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &width));
                      CFDictionarySetValue(dict, kIOSurfaceHeight, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &height));
                      CFDictionarySetValue(dict, kIOSurfacePixelFormat, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, pixelFormat));
                      CFDictionarySetValue(dict, kIOSurfaceAllocSize, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &size));
                  
                      IOSurfaceRef destSurf = IOSurfaceCreate(dict);
                      IOSurfaceAcceleratorRef outAcc;
                      IOSurfaceAcceleratorCreate(NULL, 0, &outAcc);
                  
                      CFDictionaryRef ed = (__bridge CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: nil];
                      IOSurfaceAcceleratorTransferSurface(outAcc, screenSurface, destSurf, ed, NULL);
                  
                      IOSurfaceUnlock(screenSurface, kIOSurfaceLockReadOnly, &aseed);
                  
                      CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, IOSurfaceGetBaseAddress(destSurf), (width*height*4), NULL);
                      CGImageRef cgImage=CGImageCreate(width, height, 8, 8*4, IOSurfaceGetBytesPerRow(destSurf), CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, provider, NULL, YES, kCGRenderingIntentDefault);
                      UIImage *image = [UIImage imageWithCGImage: cgImage];
                      CGImageRelease(cgImage);
                      UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
                  


                  但我得到的只是保存在我的照片文件夹中的空白图像.请帮忙看看我哪里出错了.谢谢.


                  But all I get is a blank image saved in my photos folder. Please help on what part am I going wrong. Thanks.

                  推荐答案

                  我记得我前段时间看到了一些关于这个主题的东西(在后台截屏).我无法找到我看到的确切位置和代码.我给自己留下的唯一笔记是 createScreenIOSurface 的用法

                  I remember I saw something on this subject (taking screenshots in the background) some time ago. I wasn't able find exact place and code which I saw. The only note which I left for myself was usage of createScreenIOSurface

                  我用谷歌搜索了一下,发现有几个提到:

                  I googled a little bit and found couple of mentions:

                  在应用运行时获取屏幕截图背景?(允许私有 API)

                  https://github.com/rpetrich/FastBlurredNotificationCenter/blob/master/Tweak.x

                  http://pastie.org/pastes/3734430

                  我记得代码比你展示的要紧凑.

                  As I remember the code was way more compact then what you showed.

                  这篇关于从 ios 表面创建图像并保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:iOS - 使用 StoryBoard 创建弹出视图 下一篇:在 UITableView 中隐藏页脚视图

                  相关文章

                  最新文章

                  1. <i id='7kDXQ'><tr id='7kDXQ'><dt id='7kDXQ'><q id='7kDXQ'><span id='7kDXQ'><b id='7kDXQ'><form id='7kDXQ'><ins id='7kDXQ'></ins><ul id='7kDXQ'></ul><sub id='7kDXQ'></sub></form><legend id='7kDXQ'></legend><bdo id='7kDXQ'><pre id='7kDXQ'><center id='7kDXQ'></center></pre></bdo></b><th id='7kDXQ'></th></span></q></dt></tr></i><div id='7kDXQ'><tfoot id='7kDXQ'></tfoot><dl id='7kDXQ'><fieldset id='7kDXQ'></fieldset></dl></div>

                      <small id='7kDXQ'></small><noframes id='7kDXQ'>

                        <bdo id='7kDXQ'></bdo><ul id='7kDXQ'></ul>
                    1. <tfoot id='7kDXQ'></tfoot>

                      <legend id='7kDXQ'><style id='7kDXQ'><dir id='7kDXQ'><q id='7kDXQ'></q></dir></style></legend>