我想用颜色参考着色图像.结果应该类似于Photoshop中的"乘法"混合模式,其中白色将替换为色调:

我会不断改变颜色值.
跟进:我会把代码放在我的ImageView的drawRect:方法中,对吗?
与往常一样,代码片段将极大地帮助我理解,而不是链接.
更新:使用Ramin建议的代码对UIImageView进行子类化.
我把它放在viewDidLoad中:我的视图控制器:
[self.lena setImage:[UIImage imageNamed:kImageName]];
[self.lena setOverlayColor:[UIColor blueColor]];
[super viewDidLoad];
Run Code Online (Sandbox Code Playgroud)
我看到了图像,但没有被染色.我还尝试加载其他图像,在IB中设置图像,并在我的视图控制器中调用setNeedsDisplay:
更新:drawRect:未被调用.
最后更新:我找到了一个正确设置了imageView的旧项目,所以我可以测试Ramin的代码,它就像一个魅力!
最后的最后更新:
对于那些刚学习Core Graphics的人来说,这是最简单的事情.
在您的子类UIView中:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents([UIColor colorWithRed:0.5 green:0.5 blue:0 alpha:1].CGColor)); // don't make color too saturated
CGContextFillRect(context, rect); // draw base
[[UIImage imageNamed:@"someImage.png"] drawInRect: rect blendMode:kCGBlendModeOverlay alpha:1.0]; // draw image
}
Run Code Online (Sandbox Code Playgroud) 关于如何在App中显示PDF有很多资源UIView.我现在正在做的是从中创建一个PDF UIViews.
例如,我有一个UIView,与像Textviews子视图,UILabels,UIImages,所以我怎么能转换成一个大的 UIView整体,包括其所有子视图和subsubviews到PDF?
我查看过Apple的iOS参考资料.但是,它只涉及将文本/图像片段写入PDF文件.
我面临的问题是我想以PDF格式写入文件的内容很多.如果我将它们逐个写入PDF,那将是一项巨大的工作.这就是我寻找写入UIViewsPDF甚至位图的方法的原因.
我已经尝试过在Stack Overflow中从其他Q/A复制的源代码.但它只给我一个带有UIView边界大小的空白PDF .
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
// draws rect to the view and thus this is …Run Code Online (Sandbox Code Playgroud) 当用户在我的应用程序上执行标准捏合操作时,我想放大/缩小UIImage对象.我正在使用UIImageView显示我的图像,如果该细节有任何帮助.
我正在试图弄清楚如何做到这一点,但到目前为止还没有这样的运气.
有线索吗?
我有一个叫做的图像arrowWhite.我想将此图像着色为黑色.
func attachDropDownArrow() -> NSMutableAttributedString {
let image:UIImage = UIImage(named: "arrowWhite.png")!
let attachment = NSTextAttachment()
attachment.image = image
attachment.bounds = CGRectMake(2.25, 2, attachment.image!.size.width - 2.25, attachment.image!.size.height - 2.25)
let attachmentString = NSAttributedString(attachment: attachment)
let myString = NSMutableAttributedString(string: NSString(format: "%@", self.privacyOptions[selectedPickerRow]) as String)
myString.appendAttributedString(attachmentString)
return myString
}
Run Code Online (Sandbox Code Playgroud)
我希望得到这张图片blackColour.
tintColor不管用...
我知道你可以用UIImageView做到这一点,但它可以用于UIImage吗?我想让UIImageView的动画图像数组属性成为同一图像但具有不同不透明度的数组.思考?
是否可以读取UIImageView's UIImage
目前存储在UIImageView?的名称?
我希望你能做一些像这样的事,但还没弄明白.
NSString *currentImageName = [MyIImageView getFileName];
Run Code Online (Sandbox Code Playgroud) 我一直在努力调整图像大小.基本上我已经弄明白了: 如何缩小UIImage并使其同时变得脆弱/锐利而不是模糊?
这似乎是一个合法的解决方案,但不知何故,它无法正常工作.
我的应用程序使用相机胶卷中的照片.这张照片应调整到大约200x200,而宽度很重要,而不是高度.
不幸的是,我没有示例代码,因为我在愤怒中放弃了关于非工作解决方案,对不起.
我正试图在手机上直接拍照后将图像文件上传到Parse.但它引发了一个例外:
由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'PFFile不能大于10485760字节'
这是我的代码:
在第一个视图控制器:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "getImage")
{
var svc = segue.destinationViewController as! ClothesDetail
svc.imagePassed = imageView.image
}
}
Run Code Online (Sandbox Code Playgroud)
在上传图像的视图控制器中:
let imageData = UIImagePNGRepresentation(imagePassed)
let imageFile = PFFile(name: "\(picName).png", data: imageData)
var userpic = PFObject(className:"UserPic")
userpic["picImage"] = imageFile`
Run Code Online (Sandbox Code Playgroud)
但我仍然需要将该照片上传到Parse.有没有办法减小图像的大小或分辨率?
我正在使用Swift和Parse.com 为iOS制作应用程序
我试图让用户从图像选择器中选择一张图片,然后将所选图像调整为200x200像素,然后再上传到我的后端.
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];
Run Code Online (Sandbox Code Playgroud)
如何在Swift中创建所选图片的200x200px版本(然后上传)?
而且,thumbnailImage函数在做什么?
我目前正在iOS上使用Imgur将图像上传到服务器,代码如下:
NSData* imageData = UIImagePNGRepresentation(image);
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SBTempImage.png"];
[imageData writeToFile:fullPathToFile atomically:NO];
[uploadRequest setFile:fullPathToFile forKey:@"image"];
Run Code Online (Sandbox Code Playgroud)
代码在模拟器中运行并从模拟器的照片库上传文件时工作正常,因为我在快速以太网连接上.但是,在选择使用iPhone拍摄的图像时,相同的代码会在iPhone上超时.所以,我尝试通过从网络上保存一个小图像并试图上传它,这是有效的.
这让我相信iPhone拍摄的大图像会在有点慢的3G网络上超时.有没有办法在发送之前压缩/调整iPhone的图像大小?
谢谢!
uiimage ×10
ios ×9
swift ×5
cocoa-touch ×2
uiimageview ×2
alpha ×1
colors ×1
file-upload ×1
image ×1
ios4 ×1
nsdata ×1
objective-c ×1
opacity ×1
pdf ×1
tint ×1
uiview ×1