I am Getting Unsupported Parameter Combination Cgbitmap Error with Swift

I am getting unsupported parameter combination CGBitmap error with swift

Just in case somebody is running into the same problem. The snippet below finally works.

let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(nil, UInt(rect.size.width), UInt(rect.size.height), 8, 0, colorSpace, bitmapInfo)

It generates a 32 bit RGBA context in swift

Cannot invoke initializer for type 'CGBitmapInfo' with an argument list of type '(UInt32)'

In the current version of Swift, the final parameter of CGBitmapContextCreate is a UInt32, so in place of CGBitmapInfo(options) above, you should just pass options (the expression assigned to options is inferred to have type UInt32).

What's wrong when i custom an imageView by OpenGLES?

If a non zero buffer object is bound, then the 5th parameter of glVertexAttribPointer is treated as a byte offset into the buffer object's data store.

So the offset to the texture coordinates is MemoryLayout<GLfloat>.size * 3:

glVertexAttribPointer(..., BUFFER_OFFSET(3))

glVertexAttribPointer(GLuint(textCoor), 2, GLenum(GL_FLOAT), GLboolean(GL_FALSE),
GLsizei(MemoryLayout<GLfloat>.size * 5), BUFFER_OFFSET(MemoryLayout<GLfloat>.size * 3))

How to set CGBITMAP_CONTEXT_LOG_ERRORS environmental variable?

Environmental variables can be set in the product scheme editor (in Xcode) like shown in the screenshot:

Product > Scheme > Edit Scheme... (⌘<)
Scheme editor screenshot

Can't get bytes for a non-square image

It was pretty easy to solve, actually, here's the problem part:

for x in 0..<width {
for y in 0..<height {
let byteIndex = (bytesPerRow * x) + y * bytesPerPixel

And here's how it's supposed to be:

for y in 0..<height {
for x in 0..<width {
let byteIndex = (bytesPerRow * y) + x * bytesPerPixel

I do not think this needs any further explanation.



Related Topics



Leave a reply



Submit