天道酬勤,学无止境

cgbitmapcontext

我正在迅速获得不受支持的参数组合CGBitmap错误(I am getting unsupported parameter combination CGBitmap error with swift)

问题 我正在尝试快速创建CGContext。 它可以编译,但在运行时会引发错误。 let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB() let context:CGContext = CGBitmapContextCreate(nil, 20, 20, 8, 0, colorSpace, CGBitmapInfo.AlphaInfoMask) CGColorSpaceRelease(colorSpace); .... 错误是: Error: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; unrecognized; 96 bytes/row. fatal error: Can't unwrap Optional.None 回答1 以防万一有人遇到相同的问题。 下面的代码段终于可以使用了。 let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB() let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo

2021-05-06 14:11:52    分类:技术分享    ios   swift   xcode   cgcontext   cgbitmapcontext

如何在iOS上调整位图的大小(how to resize a bitmap on iOS)

问题 我想为我正在执行的项目调整位图的大小。 我设法通过将cgbitmapcontextref转换为像素数组,然后操纵像素数组,然后从操纵的像素数据生成新图像来做到这一点。 这种方式非常麻烦。 我想知道是否还有其他方法可以调整CGBitmapContextRef的大小。 谢谢。 回答1 如果您不CGBitmapContextRef ,那么这里是一些基于UIKit的简单图像大小调整例程。 此扩展通过裁剪,缩放,宽高比填充和宽高比拟合(类似于UIImageView提供的一些主要内容模式)来提供调整图像大小的功能。 // // UIImage+Resize.swift // // Image resizing extension // // Created by Robert Ryan on 19-May-11. // Ported to Swift by Robert Ryan on 12-Feb-15. // Modified for Swift 2 by Robert Ryan on 14-Oct-15 // Modified for Swift 3 by Robert Ryan on 26-May-17 // Modified for Swift 4 by Robert Ryan on 15-Feb-19 // // Inspired by http://ofcodeandmen

2021-04-10 13:08:19    分类:技术分享    xcode   swift   cgbitmapcontext

I am getting unsupported parameter combination CGBitmap error with swift

I am trying to create a CGContext in swift. It compiles but throws an error at runtime. let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB() let context:CGContext = CGBitmapContextCreate(nil, 20, 20, 8, 0, colorSpace, CGBitmapInfo.AlphaInfoMask) CGColorSpaceRelease(colorSpace); .... And the error is: Error: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; unrecognized; 96 bytes/row. fatal error: Can't unwrap Optional.None

2021-04-09 12:02:47    分类:问答    ios   swift   xcode   cgcontext   cgbitmapcontext

how to resize a bitmap on iOS

I want to resize a bitmap for a project that I am doing. I managed to do this by converting the cgbitmapcontextref to a pixel array and then manipulating the array of pixels and then generated a new image from the manipulated pixel data. This way is extremely cumbersome. I want to know if there is any other way to resize a CGBitmapContextRef. Thanks.

2021-03-25 10:04:06    分类:问答    xcode   swift   cgbitmapcontext