我有这个扩展(找到obj-c并将其转换为Swift3)以获得相同UIImage但灰度:
public func getGrayScale() -> UIImage
{
let imgRect = CGRect(x: 0, y: 0, width: width, height: height)
let colorSpace = CGColorSpaceCreateDeviceGray()
let context = CGContext(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue).rawValue)
context?.draw(self.cgImage!, in: imgRect)
let imageRef = context!.makeImage()
let newImg = UIImage(cgImage: imageRef!)
return newImg
}
Run Code Online (Sandbox Code Playgroud)
我可以看到灰色图像,但它的质量非常糟糕......我唯一能看到的与质量相关的是bitsPerComponent: 8在上下文构造函数中.然而,看看Apple的文档,这是我得到的:
它表明iOS只支持8bpc ......那么为什么我不能提高质量呢?
这是我的问题:我试图绕UIImageView的顶角看起来像一个圆角的UIButton.我正在使用面具来做到这一点,但我得到的结果并不是我真正期待的......
我使用以下扩展名:
extension UIView
{
func roundCorners(corners:UIRectCorner, radius: CGFloat)
{
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
self.layer.mask = mask
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中调用它:
imageView.roundCorners([.TopLeft, .TopRight], radius: 80)
Run Code Online (Sandbox Code Playgroud)
这是结果: 圆角错误
我希望顶角看起来像底角(底角是半径为10的UIButton角)但是我看不到错误在哪里......
谢谢大家的帮助!
编辑:我使用正确的代码,我只是没有注意到我的UIImageView比UIImage大,因此奇怪的角落...我以编程方式创建UIImageView,因此没有注意到大小差异......新手的错误. ..
谢谢大家的帮助!
我有一个在Azure上运行的Web应用程序。我可以使用Visual Studio连接到数据库,并且可以在我的应用程序上发送/检索数据。
但是,我无法使用MySQL Workbench连接到MySQL数据库。我的错误是
Lost connection to MySQL server at 'reading initial communication packet', system error: 54
我已在Azure门户上将我的IP列入白名单,并在计算机上打开了端口1433。我不明白为什么在使用Visual Studio没问题的情况下无法使用MySQL Workbench连接。
编辑:
这是我如何设置MySQL Workbench:
这是我的Azure门户:
我正在使用端口1433,因为这是Azure门户上给出的端口,但也在本教程中:使用MySQL Workbench连接到Azure DB
我可以毫无困难地购买和恢复非消耗品。
但是,如果我尝试从从未购买过该产品的帐户中恢复,productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse)则永远不会调用该方法,而在成功恢复时会调用该方法。
这是我在类中符合SKPaymentTransactionObserver协议的代码:
public func restorePurchases() {
print("restoring...")
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()
}
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
// finishtTransaction() is called within the sub functions
switch (transaction.transactionState) {
case .purchased:
print("pruchased !")
complete(transaction: transaction)
break
case .failed:
print("failed !")
fail(transaction: transaction)
break
case .restored:
print("restored !")
restore(transaction: transaction)
break
case .deferred:
print("deferred !")
break
case .purchasing:
print("purchasing !")
break
default:
print("default...")
break
} …Run Code Online (Sandbox Code Playgroud)