搜索你感兴趣的问题
如何设置一个UIImage的不透明度/alpha
指尖的岁月袅袅 2019-06-01
分享
推荐回答
指尖的岁月袅袅 2022-01-19
1.我只需要做到这一点,但认为史蒂芬的解决方案将是缓慢的。这应该图形硬件。创建UIImage的类别:-(UIImage*)imageByApplyingAlpha:(CGFloat)alpha{UIGraphicsBeginImageContextWithOptions(self.size,NO,0.0f);CGContextRefctx=UIGraphicsGetCurrentContext();CGRectarea=CGRectMake(0,0,self.size.width,self.size.height);CGContextScaleCTM(ctx,1,-1);CGContextTranslateCTM(ctx,0,-area.size.height);CGContextSetBlendMode(ctx,kCGBlendModeMultiply);CGContextSetAlpha(ctx,alpha);CGContextDrawImage(ctx,area,self.CGImage);UIImage*newImage=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();returnnewImage;
本网站引用、摘录或转载上述内容仅供网站访问者交流或参考,文中观点或信息与爱问公司无关,与之相关的任何事务以及法律责任均与爱问公司无关。
相关推荐
有问题 @爱问
Powered by iask.com