Skip to content

Instantly share code, notes, and snippets.

@caojianhua
caojianhua / MemoryToCVPixelBuffer.m
Created December 28, 2015 07:45
Create CVPixelBuffer from memory
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;
@caojianhua
caojianhua / ImageToCVPixelBuffer.m
Last active June 10, 2017 20:48
Create CVPixelBufferRef from an UIImage
+ (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 / OpenGLToCVPixelBuffer.m
Created January 27, 2016 09:29
Create CVPixelBufferRef from OpenGL
@interface SREAGLContext : NSObject
+ (EAGLContext*)sharedContext;
+ (EAGLContext*)newContext: (EAGLRenderingAPI) api;
@end
@implementation SREAGLContext
@caojianhua
caojianhua / jarmethod.sh
Last active November 7, 2019 01:59
计算jar包文件中的方法总数
#! /bin/sh
# 获得输入的jar文件
JAR_FILE=$1;
# 这里直接使用dx命令,是因为我已经提前配置好了环境变量,dx目录位于:
# $ANDROID_HOME/sdk/build-tools/android-4.3.1/dx
dx --dex --verbose --no-strict --output=temp.dex $JAR_FILE > /dev/null
# 计算jar包中的方法数
@caojianhua
caojianhua / rename.sh
Last active August 29, 2022 07:36
Rename file to create date from exif info
#! /usr/bin/env bash
dir=$1
if [ -z "$dir" ]; then
echo "输入参数有误!"
exit
else
echo "正在处理$dir"
fi
@caojianhua
caojianhua / SimpleHTTPServerWithUpload.py
Created April 3, 2020 01:54 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""