我开发了一个应用程序,使用它的像素处理图像,但在图像处理中需要很长时间。因此,我要裁剪的UIImage(仅图像的中间部分,即去除图像/ croping接壤的部分)。我已在开发代码是,如何裁剪UIImage?
- (NSInteger) processImage1: (UIImage*) image
{
CGFloat width = image.size.width;
CGFloat height = image.size.height;
struct pixel* pixels = (struct pixel*) calloc(1, image.size.width * image.size.height * sizeof(struct pixel));
if (pixels != nil)
{
// Create a new bitmap
CGContextRef context = CGBitmapContextCreate(
(void*) pixels,
image.size.width,
image.size.height,
8,
image.size.width * 4,
CGImageGetColorSpace(image.CGImage),
kCGImageAlphaPremultipliedLast
);
if (context != NULL)
{
// Draw the image in the bitmap
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, image.size.width, image.size.height), image.CGImage);
NSUInteger numberOfPixels = image.size.width * image.size.height;
NSMutableArray *numberOfPixelsArray = [[[NSMutableArray alloc] initWithCapacity:numberOfPixelsArray] autorelease];
}
如何我拿(croping外镶上)的UIImage的中间部分? ????????
mihirpmehta , 现在我试图做类似的事情, - (UIImage *)cropedImage:(UIImage *)image { \t CGFloat width = image.size.width; \t CGFloat height = image.size.height; UIImage * cropedImage = [[UIImage alloc] init]; \t CGFloat widthCrop =(image.size.width)/ 2; \t CGFloat heightCrop =(image.size.height)/ 2; \t } 此后我无法想象要做什么? – 2010-04-14 07:25:10
将Old X + NewX/4和OldY + OldY/4换成新的X和New Y,然后使用新的宽度高度NewX和NewY制作Rectangle并将其用作cropRect – 2010-04-14 08:02:34
@mihirpmehta, 您的上述方法只是绘制原始的镜像图像在cropRect矩形中。它不能被处理UIImage。 – 2010-04-14 16:59:13