我们创建了一种方法,可以从图像中剪切圆圈,然后使用边框显示它。问题是,即使将抗锯齿设置为“true”,它看起来像这样:
您可以清楚地看到,圆形图像非常像素化。这是我们用来调试的三星S6的截图。
这是有问题的代码:
// Image file which you want to upload.
guard let image = UIImage(named: "YourImage") else { return }
let imgRep : NSBitmapImageRep = image.representations.first as! NSBitmapImageRep
let imgData : Data = imgRep.representation(using: .PNG, properties: [:])!
let cameraFileName = "some_random_name_img.png"
let fileUrl = URL(fileURLWithPath: cameraFileName, isDirectory: true)
do {
try imgData.write(to: fileUrl, options: NSData.WritingOptions.atomic)
DispatchQueue.main.async {
// Stop Camera Session if you are capturing image from camera
self.cameraSession.stopRunning()
let someParam = ""
let someParam2 = ""
let date = Date()
let dateString = "\(date)"
Alamofire.upload(multipartFormData: { (multipartFormData) in
// Add parameters in request
multipartFormData.append(cameraFileName.data(using: .utf8)!, withName: "name")
multipartFormData.append(dateString.data(using: .utf8)!, withName: "startDatetime")
multipartFormData.append(someParam.data(using: .utf8)!, withName: "userId")
multipartFormData.append(someParam2.data(using: .utf8)!, withName: "phoneServiceId")
multipartFormData.append(fileUrl, withName: "file")
}, to:"Your_Api_Url.com") // POST Url
{ (result) in
switch result {
case .success(let upload, _ , _):
upload.uploadProgress(closure: { (progress) in
print("uploding")
})
upload.responseJSON { response in
print(response)
print("done")
}
case .failure(let encodingError):
print("failed")
print(encodingError)
}
}
}
}
catch let error as NSError {
print("Ooops! Something went wrong: \(error)")
}
}
有人能暗示我们走向正确的方向吗?那太棒了:)。
谢谢!
答案 0 :(得分:1)
就像他们说的那样,您需要先绘制位图,然后在其上绘制抗锯齿圆。在生成的图像中,非抗锯齿位图绘制在圆上。