我想將一個簡單的UIImage轉換爲BitmapContext,但我找不到任何教程將UIImage轉換爲BitmapContext。請告訴我該怎麼做?UIImage BitmapContext
謝謝!
我想將一個簡單的UIImage轉換爲BitmapContext,但我找不到任何教程將UIImage轉換爲BitmapContext。請告訴我該怎麼做?UIImage BitmapContext
謝謝!
可能是這段代碼可以幫助您
CGSize newSize = CGSizeMake(320, 400);
UIGraphicsBeginImageContext(newSize);
[imageView.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(newImage);
[data writeToFile:@"foo.png" atomically:YES];
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);///save image in phone
OR For Bitmap.
CGContextRelease(context);
context = CGBitmapContextCreate (NULL,
image.size.width,
image.size.height,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaLast
);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
pixelData = CGBitmapContextGetData(context);
嘿,我想將UIImage轉換成BitmapContext並在屏幕上繪製它。我不想將它保存在相冊中。 – Smith 2012-08-03 05:08:54
告訴我什麼是像素數據?它的類型是什麼? – Smith 2012-08-03 05:37:14
請檢查以下鏈接:http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGBitmapContext/Reference/reference.html#//apple_ref/c/func/CGBitmapContextCreate – QueueOverFlow 2012-08-03 05:56:50
在您的努力? – QueueOverFlow 2012-08-03 05:19:51