iPhone:如何在使用 3d 圖層轉換時以編程方式拍攝屏幕截圖 (iPhone: how to take screen shots programmatically when using 3d layer transformations)


問題描述

iPhone:如何在使用 3d 圖層轉換時以編程方式拍攝屏幕截圖 (iPhone: how to take screen shots programmatically when using 3d layer transformations)

我正在嘗試以編程方式將當前視圖的圖像保存到 UIImage。當前視圖包含一個背景,以及許多對圖層應用了 3d 轉換的 UIImageView,例如

CATransform3D t = CATransform3DIdentity;
t = CATransform3DRotate(t, rotationX, 1.0, 0, 0);
t = CATransform3DRotate(t, rotationY, 0, 1.0, 0);
object.layer.transform = t;

我目前正在使用以下代碼抓取當前視圖的屏幕截圖:

UIGraphicsBeginImageContext(background.bounds.size);
[background.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是,對像上的 3d 變換會丟失,例如,對象會出現在保存的圖像中,就好像沒有應用 3d 變換一樣。有沒有辦法以編程方式抓取包含 3d 轉換的屏幕截圖?

UIGetScreenImage() 不是一個選項,因為它是一個私有 API,而且這個應用程序將進入應用程序商店。


## 參考解法 #### 方法 1:

I don't think it can be done at the moment, as renderInContext does not render Core Animation transforms and UIGetScreenImage() is not a public API as you well point out. The same question was asked already on StackOverflow:

1) How do I create/render a UIImage from a 3D transformed UIImageView?

2) CALayer renderInContext

If that feature is key to your application, I'd look into using an OpenGL view and capturing the color buffer (which can be rendered offscreen if you don't want to display it).

(by AndrewJulio Gorgé)

參考文件

  1. iPhone: how to take screen shots programmatically when using 3d layer transformations (CC BY‑SA 3.0/4.0)

#screenshot #iphone #layer #transform #rotation






相關問題

沒有 iPhone,如何使用 XCode 截屏? (Without iPhone, how to take screenshot with XCode?)

mapViewDidFinishLoadingMap:調用過早 (mapViewDidFinishLoadingMap: called too early)

屏幕截圖上的窗口沒有消失 (Window not disappearing on Screenshot)

Appium 中用於混合應用程序的多個屏幕截圖 (Multiple Screenshots in Appium for Hybrid Apps)

在Linux上通過Python腳本拍攝屏幕截圖 (Take a screenshot via a Python script on Linux)

如何使用服務器端腳本生成網頁的屏幕截圖? (How can I generate a screenshot of a webpage using a server-side script?)

如何使用 ruby 和 unix 服務器截取網頁截圖? (How do I take screenshots of web pages using ruby and a unix server?)

使用 jquery 生成網站的屏幕截圖 (generating a screenshot of a website using jquery)

畫面區域的選擇 (Selection of screen area)

使用 PHP 的網頁截圖? (Web Page Screenshots with PHP?)

iPhone:如何在使用 3d 圖層轉換時以編程方式拍攝屏幕截圖 (iPhone: how to take screen shots programmatically when using 3d layer transformations)

防止 VideoView Activity 中的視頻屏幕截圖 - Android (Prevent Video screen capture in VideoView Activity - Android)







留言討論