【问题标题】:Change transparency for UIImage (not UIImageView)更改 UIImage 的透明度(不是 UIImageView)
【发布时间】:2012-03-31 08:16:05
【问题描述】:

我正在使用 AVAssetWriterInputPixelBufferAdaptor 从 UIImage 数组创建视频, 我想以不同形式的动画改变从一个图像到另一个图像的过渡(很像幻灯片......实际上就像幻灯片一样)。

其中一种过渡样式是淡出。 因为我像这样写 UIImages ..

    UIImage *image = imageView.image;
    UIImage *resizedImage = [ICVideoViewController imageWithImage:image scaledToSize:CGSizeMake(640, 480)];
    CGImageRef img = [resizedImage CGImage];
    CVPixelBufferRef buffer = [ICVideoViewController pixelBufferFromCGImage:img size:CGSizeMake(640, 480)];

    [adaptor appendPixelBuffer:buffer withPresentationTime:CMTimeMake(i, 1)];

我想知道是否有可能(无需手动操作像素) 为达到这个 .. ?

【问题讨论】:

    标签: iphone objective-c ios ipad uiimage


    【解决方案1】:

    混合你正在转换的两个图像怎么样?

    请参阅以下主题:blend two uiimages based on alpha/transparency of top image

    【讨论】:

      【解决方案2】:

      我不知道您是如何在视图控制器的 imagawithimage 函数中创建图像的。

      如果您使用 CGContext 来缩放图像,请在 CGContextDrawImage() 之前使用 CGContextSetAlpha()

      如果不能,您可以再做一件事,毫无疑问,您需要为此编写几行代码,但这可能是一种方法:

      CGSize size = [self size];
      int width = size.width;
      int height = size.height;
      
      // the pixels will be painted to this array
      uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
      
      // clear the pixels so any transparency is preserved
      memset(pixels, 0, width * height * sizeof(uint32_t));
      
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
      
      // create a context with RGBA pixels
      CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, 
                                                   kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
      
      // paint the bitmap to our context which will fill in the pixels array
      CGContextSetAlpha(context, 0.5);
      CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]);
      CGImageRef image = CGBitmapContextCreateImage(context);
      
      CGContextRelease(context);
      CGColorSpaceRelease(colorSpace);
      free(pixels);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-04
        • 2012-09-20
        • 1970-01-01
        • 2010-12-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多