Xcode 调试 - 显示图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2780793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:23:35  来源:igfitidea点击:

Xcode debugging - displaying images

xcodedebugging

提问by krasnyk

I love using the Xcode debugger. You can take a look at a variable's value and even change it.

我喜欢使用 Xcode 调试器。您可以查看变量的值,甚至更改它。

But can I somehow DISPLAY the image that is referenced by an image variable? I know I can see its raw bytes, but it would be much more human-friendly to display a window with its contents.

但是我可以以某种方式显示图像变量引用的图像吗?我知道我可以看到它的原始字节,但是显示一个包含其内容的窗口会更加人性化。

Xcode might not support this. Maybe there is an external tool that would help display images?

Xcode 可能不支持这一点。也许有一个外部工具可以帮助显示图像?

回答by pkamb

Use Quick Lookto inspect images in the Xcode debugger.

使用Quick Look在 Xcode 调试器中检查图像。

Select an NSImageor UIImagein the debugger, then click the Quick Look "eye" icon.

在调试器中选择一个NSImageUIImage,然后单击快速查看“眼睛”图标。

"eye" icon in Xcode debugger toolbar

Xcode 调试器工具栏中的“眼睛”图标

Like other areas of OS X, you can also use spacebarto Quick Look!

与 OS X 的其他领域一样,您也可以使用spacebarQuick Look!

Viewing a UIImage in the Xcode debugger via Quick Look

通过 Quick Look 在 Xcode 调试器中查看 UIImage

Quick Look in the debugger can also be implemented for your own classes:

调试器中的快速查看也可以为您自己的类实现:

Enabling Quick Look for Custom Types

为自定义类型启用快速查找

The variables Quick Look feature in the Xcode debugger allows you to obtain a quick visual assessment of the state of an object variable through a graphical rendering, displayed in a popover window either in the debugger variables view or in place in your source code.

This chapter describes how you implement a Quick Look method for your custom class types so that object variables of those types can also be rendered visually in the Quick Look popover window.

Xcode 调试器中的 variables Quick Look 功能允许您通过图形渲染获得对象变量状态的快速视觉评估,显示在调试器变量视图或源代码中的弹出窗口中。

本章介绍如何为自定义类类型实现 Quick Look 方法,以便这些类型的对象变量也可以在 Quick Look 弹出窗口中可视化呈现。

回答by Avi Shukron

EDIT:

编辑:

As of Xcode 5, the debugger can show you the visual representation of UIImage/CGImageRef variables!

从 Xcode 5 开始,调试器可以向您展示 UIImage/CGImageRef 变量的可视化表示!

Xcode itself can't do it. I don't know about external tools.

Xcode 本身做不到。我不知道外部工具。

What i'm doing to test images while debugging is to convert that raw data into an image-file format, like .png, and then saving it somewhere, and then i'm opening the image with any image viewing tool.

我在做什么测试图像,同时调试到原始数据转换为图像文件格式,如png格式,然后保存到某个地方,然后我与任何图像查看工具打开图像。

I have a piece of code for that purpose, which look basically like that:

为此,我有一段代码,它看起来基本上是这样的:

NSData *imageData = UIImagePNGRepresentation(self.myUIImage);
[imageData writeToURL:desktopURL atomically:YES];

And i'm just copy-pasting this code where i want to see content of an image on the run.

我只是将这段代码复制粘贴到我想在运行时查看图像内容的地方。

Make sure to get rid of this code as soon as possible due to the high-cost of the conversion of UIImageto NSData

一定要得到很快摆脱这个代码尽可能由于转换的高成本UIImageNSData

回答by mackworth

Edit for Xcode 5:

为 Xcode 5 编辑:

Now when you hover over a image variable name, there will be an "eye" icon on the right. Just click it to see the current image! If you don't have a UIImage variable (e.g. it's a property of another object, you can still use the older answer:

现在,当您将鼠标悬停在图像变量名称上时,右侧会出现一个“眼睛”图标。只需单击它即可查看当前图像!如果您没有 UIImage 变量(例如,它是另一个对象的属性,您仍然可以使用旧答案:

Older answer: Old question, but I was searching for an answer. Starting with Avraham's answer, I tried a few experiments for displaying an iOS image from lldb without having to recompile or add it to a view. I finally came up with:

较旧的答案:旧问题,但我正在寻找答案。从 Avraham 的回答开始,我尝试了一些实验来显示 lldb 中的 iOS 图像,而无需重新编译或将其添加到视图中。我终于想出了:

po [UIImagePNGRepresentation(watchImage) writeToFile:@"/Users/<userName>/Desktop/watchImage.png" atomically:NO];

I keep this string in a text editor and paste it when I need it. This stores the current image I'm interested in (in this case, "watchImage") to a PNG file on the Desktop. Then I can just open this file with Preview.

我将此字符串保存在文本编辑器中,并在需要时粘贴它。这会将我感兴趣的当前图像(在本例中为“watchImage”)存储到桌面上的 PNG 文件中。然后我可以用预览打开这个文件。

回答by Zaster

If you like to work with the lldb console, use chiselcommand "visualize"

如果您喜欢使用 lldb 控制台,请使用chisel命令“visualize”

tip:

提示:

after the installation, you can set a conditional breakpoint after setting the UIImage with the action: "visualize myUIImageToShowWithQuickLook"

安装后,您可以在设置 UIImage 后设置条件断点,操作如下:“visualize myUIImageToShowWithQuickLook”

enter image description here

在此处输入图片说明

this will show you the image automatically when the debugger stops.

这将在调试器停止时自动显示图像。

回答by wyu

What if you can't get to the image via the variables view?

如果无法通过变量视图访问图像怎么办?

Echoing what @pkamb said - you can use the variables view to quick look at an image. But what if you can't get to the image?

回应@pkamb 所说的 - 您可以使用变量视图快速查看图像。但是,如果您无法获得图像怎么办?

for example I have an image at (contentViewController.view.subviews[0].subviews[1] as? UIImageView).image

例如我有一张图片 (contentViewController.view.subviews[0].subviews[1] as? UIImageView).image

but if I try to expand contentViewControllerin the variable view it doesn't expose my subviews

但是如果我尝试contentViewController在变量视图中展开它不会暴露我的子视图

enter image description here

在此处输入图片说明

what you can do is right click, add an expression, and then you can see it!

你可以做的就是右键单击,添加一个表达式,然后你就可以看到了!

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Malloc

You can put a breakpoint in the line of your image, and then in the debugger, just write:

您可以在图像的行中放置一个断点,然后在调试器中,只需编写:

po your_UIImage_object

postands for print object, it's a GDB command which will display several useful informations about the object passed, in your case the image.

po代表print object,它是一个 GDB 命令,它将显示有关传递的对象的一些有用信息,在您的情况下是图像。