gpt4 book ai didi

ios - 在gif动画上添加label和imageview并分享gif动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:08 25 4
gpt4 key购买 nike

我正在开发图片说明应用。对于普通的 png 图片,一切正常,但我的客户要求我从图像创建动画 gif。我已经使用 imageview 动画属性创建了动画 gif,但是当我必须在 gif 图像上添加标题并共享带有标题的 gif 图像时,问题就来了。我通过将它们转换为 NSdata 来共享简单的 gif 图像。请告诉我在动画 gif 上添加标题的正确方法。我使用下面的代码创建了 gif 图像

 CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:path]),kUTTypeGIF,[camImages count],NULL);
NSDictionary *frameProperties = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject: [NSNumber numberWithInt:2] forKey:(NSString *)@"0.15f"]
forKey:(NSString *)kCGImagePropertyGIFDictionary];
NSDictionary *gifProperties = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCGImagePropertyGIFLoopCount]
forKey:(NSString *)kCGImagePropertyGIFDictionary];

_image=[[UIImage alloc] init];
for(int i=0;i<camImages.count;i++)
{
_image =[camImages objectAtIndex:i];
CGImageDestinationAddImage(destination, _image.CGImage, (CFDictionaryRef)CFBridgingRetain(frameProperties));
}
CGImageDestinationSetProperties(destination, (CFDictionaryRef)CFBridgingRetain(gifProperties));
CGImageDestinationFinalize(destination);

最佳答案

你有 gif 的每一帧,所以你可以在 gif 的每个图像的相同位置上绘制标题,然后你得到新的图像,你将把它们组合成一个新的 gif。

How to write text on image

这是一个旋转文本演示。

NSString * str = @"hello" ;
UIImage * image = [UIImage imageNamed:@"path"] ;
CGSize imageSize = image.size ;
UIGraphicsBeginImageContextWithOptions(imageSize, YES, 0.0) ;
[image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)] ;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextRotateCTM(context, M_PI);
[[UIColor whiteColor] set] ;
[str drawInRect:CGRectMake(-imageSize.width, -imageSize.height, imageSize.width, imageSize.height) withFont:[UIFont systemFontOfSize:16.0]] ;
CGContextRestoreGState(context);
UIImage * compressedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

关于ios - 在gif动画上添加label和imageview并分享gif动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21397849/

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