Skip to content

Instantly share code, notes, and snippets.

caojianhua caojianhua

Block or report user

Report or block caojianhua

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@caojianhua
caojianhua / OpenGLToCVPixelBuffer.m
Created Jan 27, 2016
Create CVPixelBufferRef from OpenGL
View OpenGLToCVPixelBuffer.m
@interface SREAGLContext : NSObject
+ (EAGLContext*)sharedContext;
+ (EAGLContext*)newContext: (EAGLRenderingAPI) api;
@end
@implementation SREAGLContext
@caojianhua
caojianhua / ImageToCVPixelBuffer.m
Last active Jun 10, 2017
Create CVPixelBufferRef from an UIImage
View ImageToCVPixelBuffer.m
+ (CVPixelBufferRef)pixelBufferFromImage:(UIImage *)image {
NSData * rawImageData = [UIImage RawRepresentation:image pixelFormat:SVPixelFormat_BGRA];
NSDictionary * attributes = @{
(NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{},
(NSString *)kCVPixelBufferCGImageCompatibilityKey : @(YES),
(NSString *)kCVPixelBufferOpenGLESCompatibilityKey : @(YES),
(NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey : @(YES),
};
@caojianhua
caojianhua / MemoryToCVPixelBuffer.m
Created Dec 28, 2015
Create CVPixelBuffer from memory
View MemoryToCVPixelBuffer.m
CVPixelBufferRef pxbuffer = NULL;
CVPixelBufferCreateWithBytes(kCFAllocatorDefault,width,height,kCVPixelFormatType_32ARGB,data,4 * width, NULL, NULL, NULL, &pxbuffer);
CIImage* tmpImage = [CIImage imageWithCVPixelBuffer:pxbuffer];
UIImage* newImage = [UIImage imageWithCIImage:tmpImage];
NSLog(@"imageSize:%@",NSStringFromCGSize(newImage.size));
dispatch_async(dispatch_get_main_queue(), ^{
imageView.image = newImage;
You can’t perform that action at this time.