Created
October 26, 2011 18:53
-
-
Save naoya/1317396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns a copy of the image that has been transformed using the given affine transform and scaled to the new size | |
// The new image's orientation will be UIImageOrientationUp, regardless of the current image's orientation | |
// If the new size is not integral, it will be rounded up | |
+ (UIImage *)resizedImage:(CGSize)newSize | |
transform:(CGAffineTransform)transform | |
drawTransposed:(BOOL)transpose | |
interpolationQuality:(CGInterpolationQuality)quality | |
image:(UIImage*)image | |
hires:(BOOL)hires | |
{ | |
// なぜこれで意図通りに動くんだ... | |
return image; | |
// CGImageRef imageRef = image.CGImage; | |
// CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
// CGFloat scale = 1.0; | |
// #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 | |
// if ([TiUtils isIOS4OrGreater]) { | |
// scale = [image scale]; | |
// // Force scaling to 2.0 | |
// if ([TiUtils isRetinaDisplay] && hires) { | |
// scale = 2.0; | |
// } | |
// } | |
// #endif | |
// CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width*scale, newSize.height*scale)); | |
// CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width); | |
// // Build a context that's the same dimensions as the new size | |
// CGContextRef bitmap = CGBitmapContextCreate(NULL, | |
// newRect.size.width, | |
// newRect.size.height, | |
// 8, | |
// 0, | |
// colorSpace, | |
// kCGImageAlphaPremultipliedLast); | |
// // Rotate and/or flip the image if required by its orientation | |
// CGContextConcatCTM(bitmap, transform); | |
// // Set the quality level to use when rescaling | |
// CGContextSetInterpolationQuality(bitmap, quality); | |
// // Draw into the context; this scales the image | |
// CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef); | |
// // Get the resized image from the context and a UIImage | |
// CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap); | |
// UIImage *newImage = nil; | |
// if ([TiUtils isIOS4OrGreater]) { | |
// newImage = [UIImage imageWithCGImage:newImageRef scale:scale orientation:UIImageOrientationUp]; | |
// } | |
// else { | |
// newImage = [UIImage imageWithCGImage:newImageRef]; | |
// } | |
// // Clean up | |
// CGContextRelease(bitmap); | |
// CGImageRelease(newImageRef); | |
// CGColorSpaceRelease(colorSpace); | |
// return newImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment