ios - invalid data bytes/row:CGBitmapContextCreate: CGContextDrawImage: invalid context 0x0 -
i'm trying convert array of images video file. in process have fill pixel buffer selected images. here code snippet:
cvpixelbufferlockbaseaddress(pixelbuffer, 0) let pixeldata = cvpixelbuffergetbaseaddress(pixelbuffer) let bitmapinfo:cgbitmapinfo = cgbitmapinfo(rawvalue: cgimagealphainfo.premultipliedfirst.rawvalue) let rgbcolorspace = cgcolorspacecreatedevicergb() print("\npixel buffer width: \(cvpixelbuffergetwidth(pixelbuffer))\n") print("\nbytes per row: \(cvpixelbuffergetbytesperrow(pixelbuffer))\n") let context = cgbitmapcontextcreate( pixeldata, int(image.size.width), int(image.size.height), cgimagegetbitspercomponent(image.cgimage), cvpixelbuffergetbytesperrow(pixelbuffer), rgbcolorspace, bitmapinfo.rawvalue ) cgcontextdrawimage(context, cgrectmake(0, 0, image.size.width, image.size.height), image.cgimage) cvpixelbufferunlockbaseaddress(pixelbuffer, 0)
after executing these lines following message in xcode: cgbitmapcontextcreate: invalid data bytes/row: should @ least 13056 8 integer bits/component, 3 components, kcgimagealphapremultipliedfirst.cgcontextdrawimage: invalid context 0x0. after debugging following value:
cvpixelbuffergetwidth(pixelbuffer) // value 480 cvpixelbuffergetbytesperrow(pixelbuffer) // value 1920
what should valid data bytes/row? 3 components specified in console log? saw similar questions in stackoverflow nothing helped in case.
Comments
Post a Comment