gpt4 book ai didi

iphone - 如何向 UIImage 或 UIImageView 或 UIView 添加外部发光

转载 作者:行者123 更新时间:2023-12-03 18:32:25 24 4
gpt4 key购买 nike

我想向 UIImage 添加褪色阴影/外发光/UIImageView/UIView但我不知道Core Graphics根本不。

编辑:请帮忙!!

最佳答案

采用 Cirrostratus 概述的方法,保留其缓存副本,然后在拖动时应用变换来更改图像的大小和/或位置。

(警告,这不是功能/测试代码,但应该可以帮助您入门)

-(UIImage*)addGlowToImage:(UIImage*)imageInput;
{
CGRect newSize = imageInput.bounds;
CGImageRef theImage = imageInput.CGImage;

// expand the size to handle the "glow"
newSize.size.width += 6.0;
newSize.size.height += 6.0;
UIGraphicsBeginImageContext(newSize);
CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextBeginTransparencyLayerWithRect(ctx, newSize, NULL);
CGContextClearRect(ctx, newSize);

// you can repeat this process to build glow.
CGContextDrawImage(ctx, newSize, theImage);
CGContextSetAlpha(ctx, 0.2);

CGContextEndTransparencyLayer(ctx);

// draw the original image into the context, offset to be centered;
CGRect centerRect = inputImage.bounds;
centerRect.origin.x += 3.0;
centerRect.origin.y += 3.0;
CGContextDrawImage(ctx, centerRect, theImage);

result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return result;
}

然后在您的方法中,在缩放时您会执行以下操作:

// assumes UIImage *cachedImage = [self addGlowToImage:origImage]; has been called already.
// assumes ivars for scale exists

CGRect newRect = cachedImage.bounds;
newRect.size.width += scale;
newRect.size.height += scale;

[cachedImage drawInRect:newRect]; // image will be scaled to fill destination rectangle.

一定要看看苹果文档。一个好的起点是 Quartz 2D Programming Guide .

关于iphone - 如何向 UIImage 或 UIImageView 或 UIView 添加外部发光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2278440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com