Tag: uiimage

如何捕捉UIView顶部UIView

我有显示graphics的UIView ..现在我需要将其捕获到UIImage ,我GOOGLE了它,并得到了下面的code.but如果我在我的代码中使用它不工作。即使我使用断点编译器没有达到这个。我在我的UIView使用这个,我错了? + (UIImage *) imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; }

如何在Swift中调整图像大小?

我正在使用Swift和Parse.com为iOS创build一个应用程序 我试图让用户从图像select器中select一张图片,然后在上传到我的后端之前将所选图像的大小调整为200×200像素。 Parse.com有一个名为“AnyPic”的Instagram复制应用程序的教程,它给出了调整图像大小的代码,但它在Objective-C中。 // Resize the image to be square (what is shown in the preview) UIImage *resizedImage = [anImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:CGSizeMake(560.0f, 560.0f) interpolationQuality:kCGInterpolationHigh]; // Create a thumbnail and add a corner radius for use in table views UIImage *thumbnailImage = [anImage thumbnailImage:86.0f transparentBorder:0.0f cornerRadius:10.0f interpolationQuality:kCGInterpolationDefault]; 如何在Swift中创build200x200px的选定图片(然后上传)? 而且,thumbnailImage函数在做什么?

iOS UIImage剪辑到path

我正在处理用户使用UIBezierPathselect其中一部分的图像。 我如何删除/清除/透明所有不属于该select的内容?

用phimagemanager保存图像到自定义相册?

我正在制作一个应用程序,用AVFoundation拍照,我想将它们保存到一个自定义相册,然后我可以查询和显示在我的应用程序。 (除非用户需要,否则我不希望在普通照片中包含这些内容)我无法在Swift中find任何显示如何执行此操作的内容。 有没有不同的方式,我应该这样做? 我在SO上find了这个例子,但对我来说没有任何意义,我也无法使它起作用。 func savePhoto() { var albumFound : Bool = false var assetCollection: PHAssetCollection! var photosAsset: PHFetchResult! var assetThumbnailSize:CGSize! // Create the album if does not exist (in viewDidLoad) if let first_Obj:AnyObject = collection.firstObject{ //found the album self.albumFound = true self.assetCollection = collection.firstObject as PHAssetCollection }else{ //Album placeholder for the asset collection, used […]

Swift PNG图像以不正确的方向保存

如果在保存之前使用图像,则是正常的。 但是,如果我保存并在以后使用它是90度转向。 我怎样才能确保它不会横向保存? func saveEvent(_ center1: CLLocation, title2: String, imagePicked1: UIImage) { let data = UIImagePNGRepresentation(imagePicked1);/// let url = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(NSUUID().uuidString+".dat") do { try data!.write(to: url!, options: []) } catch let e as NSError { print("Error! \(e)"); return } let image11 = CKAsset(fileURL: url!) self.eventRecord.setObject(image11 as CKAsset, forKey: "Picture") let publicData = CKContainer.default().publicCloudDatabase publicData.save(self.eventRecord, completionHandler: […]

UICollectionView将图像添加到单元格

我正在使用UICollectionView来显示可能有或没有图像的数据的项目。 我使用的方式是检查图像的URL不是null,然后将一个ImageView添加到单元格。 – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (question.picture != (id)[NSNull null]) { //add AsyncImageView to cell imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.clipsToBounds = YES; imageView.tag = IMAGE_VIEW_TAG; [cell addSubview:imageView]; [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageView]; imageView.imageURL = [NSURL URLWithString:question.picture]; } } 对于那些没有图像的单元格,单元格应该如下所示: https : //dl.dropboxusercontent.com/u/5753236/Stackoverflow/good.png 但是,他们中的一些仍然会添加一个带有裁剪图像的ImageView,导致如下所示: https : //dl.dropboxusercontent.com/u/5753236/Stackoverflow/bad.png 我试过使用SDWebImage,但仍然没有解决问题。 另一个问题是当我向下滚动UICollectionView ,会看到一些图像显示为上面显示的图像,然后在加载完成后切换到正确的图像,我不知道是什么导致了问题。 请帮我解决这两个问题,我真的很感激任何帮助。

如何用六angular形蒙版圆angularUIImage

我试图添加一个六边形蒙版到我已经成功的UIImage。但是我无法圆六边形蒙版的两侧。 我想joincell.profilePic.layer.cornerRadius = 10; 会做的伎俩,但它没有。 这是我的代码: CGRect rect = cell.profilePic.frame; CAShapeLayer *hexagonMask = [CAShapeLayer layer]; CAShapeLayer *hexagonBorder = [CAShapeLayer layer]; hexagonBorder.frame = cell.profilePic.layer.bounds; UIBezierPath *hexagonPath = [UIBezierPath bezierPath]; CGFloat sideWidth = 2 * ( 0.5 * rect.size.width / 2 ); CGFloat lcolumn = ( rect.size.width – sideWidth ) / 2; CGFloat rcolumn = rect.size.width – […]

将UIImage切成一个圆Swift(iOS)

我想把一个UIImage切成一个圆,这样我就可以用它作为注释。 我发现这个网站上的每一个答案都描述了创build一个UIImageView ,然后修改并显示它,但是你不能将一个注释的图像设置为一个UIImageView ,只有一个UIImage 。 我应该怎么做呢?

是编程颠倒可能的图像的颜色?

我想拍摄一张图片,并在iOS中反转颜色。

如何使用Swift获取UIImage中的像素的颜色?

我试图用Swift获取UIImage中的一个像素的颜色,但它似乎总是返回0.这里是代码,从@Minas的这个线程的答案翻译: func getPixelColor(pos: CGPoint) -> UIColor { var pixelData = CGDataProviderCopyData(CGImageGetDataProvider(self.CGImage)) var data: UnsafePointer<UInt8> = CFDataGetBytePtr(pixelData) var pixelInfo: Int = ((Int(self.size.width) * Int(pos.y)) + Int(pos.x)) * 4 var r = CGFloat(data[pixelInfo]) var g = CGFloat(data[pixelInfo+1]) var b = CGFloat(data[pixelInfo+2]) var a = CGFloat(data[pixelInfo+3]) return UIColor(red: r, green: g, blue: b, alpha: a) } 提前致谢!