象图像这样的明显声音是大的,因此在装上。 我建议你要么使用较小的图像,要么如果你不控制这些图像,那么你可能会试图在背景中填满图像。 下面是一些守则,使你开始装上底线:
- (void)decodeImageInBackgroundThread:(UIImage*)decodedImage forImageView:(UIImageView*)imageView {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
CGImageRef originalImage = [decodedImage CGImage];
CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(originalImage));
CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData(imageData);
if (imageData != NULL) {
CFRelease(imageData);
}
CGImageRef image = CGImageCreate(CGImageGetWidth(originalImage),
CGImageGetHeight(originalImage),
CGImageGetBitsPerComponent(originalImage),
CGImageGetBitsPerPixel(originalImage),
CGImageGetBytesPerRow(originalImage),
CGImageGetColorSpace(originalImage),
CGImageGetBitmapInfo(originalImage),
imageDataProvider,
CGImageGetDecode(originalImage),
CGImageGetShouldInterpolate(originalImage),
CGImageGetRenderingIntent(originalImage));
if (imageDataProvider != NULL) {
CGDataProviderRelease(imageDataProvider);
}
dispatch_async(dispatch_get_main_queue(), ^{
[imageView setImage:[UIImage imageWithCGImage:image]];
CGImageRelease(image);
});
});
}
你们可以这样作:
- (void)viewDidLoad {
...
UIImage *image = [UIImage imageNamed:@"hello.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:nil];
[imageView setFrame:CGRectMake(0.0f, 0.0f, 200.0f, 300.0f)];
[[self view] addSubview:imageView];
[self decodeImageInBackgroundThread:image forImageView:imageView];
}