- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想知道如何使用 UIImagePicker 从相机库中始终选择方形图像?
所以我设置了 imagePicker.allowsEditing = true
并且当我选择的图像足够大(大于正方形裁剪)时,选择的图像是正方形的。但是,当我选择的图像较小时,假设它是 748 x 466,即使正方形裁剪包围了包括顶部和底部黑色部分的图像,但选择的图像不包括黑色部分,因此它返回一个非正方形图片。我如何让它始终选择黑色的顶部和底部,使图像始终为正方形?
非常感谢您的帮助!
最佳答案
这里是使用 CoreGraphics 手动添加黑色区域的方法,在 UIImagePicker 委托(delegate)方法中添加:
let squareSideLength = image.size.width > image.size.height ? image.size.width : image.size.height
UIGraphicsBeginImageContextWithOptions(CGSizeMake(squareSideLength, squareSideLength), false, 1)
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, UIColor.blackColor().CGColor)
CGContextFillRect(context, CGRectMake(0, 0, squareSideLength, squareSideLength))
image.drawInRect(CGRectMake((squareSideLength - image.size.width) / 2, (squareSideLength - image.size.height) / 2, image.size.width, image.size.height))
let imageYouWant = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
然后使用imageYouWant
。
关于ios - UIImagePicker : How to always pick square image from camera library?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33611310/
有什么区别 import { pick } from 'lodash'; 和 import pick from 'lodash/pick'; (请注意,第二个是'lodash/pick',而不仅仅是'
我试图只让祖先的一些属性暴露在我的后代上。我尝试通过Pick来实现 export class Base { public a; public b; public c; } ex
我这里有 2 个分支,比如 branch1 和 branch2。 branch1 增加了很多新功能,branch2 是稳定的。今天,我只想将 1 个功能从 branch1 merge 到 branch
我正在尝试使用 git rebase -i HEAD~19 删除提交列表。我过去曾成功地使用过此方法,但是当我尝试运行然后退出 vim 而不进行任何更改(:q!)时,我收到此错误: The previ
我正在使用网格主题并尝试完成默认为“选择尺寸”而不是product.liquid 中的“小”的自定义。 (客户看到太多来自订购默认尺寸的人的错误“小”订单)。 解决这个问题: https://docs
我想输入一个名为 pick 的函数,我知道 typescript 内置了 Pick ,现在我想实现实际的源码使用部分,但是我卡住了。 这个函数的作用是pick提供object基于给定字符串的属性并返回
我有一个用例,我认为它非常适合 Typescript 的 Pick类型。 这是一个简化的例子: interface CreditCard { name: string; year: numbe
假设我有分支 A 和 B。 A: a b c d B: a b c e 我想从分支 B 获取提交 e 并将其放在分支 A 的提交 d 下。所以我最后的结果应该是这样的 A: a b c e d 怎么做
我有两个 pandas 数据框,data1 和 data2 它们显示在图表上。我可以点击该点来显示该点的信息。但仅来自一个数据集。如何将它用于两个数据集?我还需要显示来自另一个通过索引访问数据的数组的
我是 git 的新手,我确实了解 git cherry-pick 的工作原理,但这是我的问题: 最近,我的团队中有人更改了 master 中的目录结构,但没有更改另一个分支中的目录结构。 现在,当我在
我在大学里使用 git 大约几年了,老实说,我仍然不知道自己在做什么。 我不确定我的标题是否恰本地描述了我遇到的问题,但基本上,在开发特定功能时,我已经向 master 分支提交了一堆。现在我已完成开
我有两个具有相似架构的存储库: repo1: - file1 - file2 *(this file is non-existent in repo2) - folder - file3
我一直在尝试从一个分支中挑选一个特定的提交到另一个分支。假设我的历史是这样的: A - B - C - D (master) \ X - Y (feature)
如果我将这一行用作数组,我不确定为什么会出现问题以及如何修复它: Pick[] Sandbox . 如果我使用 never 而不是条件类型,那么必填作者字段就会出现另一个问题。 Sanbox 2 沙盒
我不太了解 cherry-pick。只需要清除 cherry-pick 命令在不同分支中生成相同提交的不同哈希码?实际上,我正在挑选不同分支中的哈希码。在这里我注意到它正在生成现有提交的不同哈希码。是
picks :: [a] -> [(a, [a])] picks [] = [] picks (x:xs) = (x,xs) : [(y,x:ys)| (y,ys) <- picks xs] pick
我已经单独尝试了 Num((today()-I_TRAN_DATE)/90 + 1,0) 并且它会返回整数,但是当我尝试将它与 pick 函数结合使用时它似乎不起作用。我知道它还没有完成,但至少应该返
此问题专门针对 Minecraft,但它会影响我计算机上运行的所有 Java 程序。 似乎有什么东西强行设置了 _JAVA_OPTIONS 环境变量。当我运行我的服务器时,我已指定为其分配 4 GB
我想知道是否有办法将一个提交复制到另一个分支而不检查该分支。 例如,我有两个分支:master和 parallel_version . 我在 parallel_version分支,我在这些分支的常见文
给定以下内容: 1 1 4 2
我是一名优秀的程序员,十分优秀!