이것은 내가 돌아 왔을 때 발견 한 코드 중 하나이며 내 UIView 확장에 사용합니다. 확실하지 그것을 위해 신용 있지만, 여기있다 할 사람 :
- (UIImage *)overlayWithImage:(UIImage *)image2 {
UIImage *image1 = self;
CGRect drawRect = CGRectMake(0.0, 0.0, image1.size.width, image1.size.height);
// Create the bitmap context
CGContextRef bitmapContext = NULL;
void * bitmapData;
int bitmapByteCount;
int bitmapBytesPerRow;
CGSize size = CGSizeMake(image1.size.width, image1.size.height);
// Declare the number of bytes per row. Each pixel in the bitmap in this
// example is represented by 4 bytes; 8 bits each of red, green, blue, and
// alpha.
bitmapBytesPerRow = (size.width * 4);
bitmapByteCount = (bitmapBytesPerRow * size.height);
// Allocate memory for image data. This is the destination in memory
// where any drawing to the bitmap context will be rendered.
bitmapData = malloc(bitmapByteCount);
if (bitmapData == NULL) {
return nil;
}
// Create the bitmap context. We want pre-multiplied ARGB, 8-bits
// per component. Regardless of what the source image format is
// (CMYK, Grayscale, and so on) it will be converted over to the format
// specified here by CGBitmapContextCreate.
bitmapContext = CGBitmapContextCreate (bitmapData, size.width, size.height,8,bitmapBytesPerRow, CGColorSpaceCreateDeviceRGB(),kCGImageAlphaNoneSkipFirst);
if (bitmapContext == NULL)
// error creating context
return nil;
// Draw the image to the bitmap context. Once we draw, the memory
// allocated for the context for rendering will then contain the
// raw image data in the specified color space.
CGContextDrawImage(bitmapContext, drawRect, [image1 CGImage]);
CGContextDrawImage(bitmapContext, drawRect, [image2 CGImage]);
CGImageRef img = CGBitmapContextCreateImage(bitmapContext);
UIImage* ui_img = [UIImage imageWithCGImage: img];
CGImageRelease(img);
CGContextRelease(bitmapContext);
free(bitmapData);
return ui_img;
}
- 내가 합병증없이 백그라운드 스레드에서 사용합니다.
+1. 예 ... 아주 간단합니다. –