嗨,有什么方法可以在 iPhone SDK 中将您的图像瘦尺寸更改为胖尺寸,反之亦然?
在这个应用程序中,我想为用户提供一种通过滑动滑块将其图像从常规尺寸更改为胖尺寸的可能性,他可以在 iPhone SDK 中测量其尺寸?我认为这可以通过获取图像的像素来实现我已经尝试过这段代码来获取图像的像素,但它只是从图像中删除了颜色。
UIImage *image = [UIImage imageNamed:@"foo.png"];
CGImageRef imageRef = image.CGImage;
NSData *data = (NSData *)CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
char *pixels = (char *)[data bytes];
// this is where you manipulate the individual pixels
// assumes a 4 byte pixel consisting of rgb and alpha
// for PNGs without transparency use i+=3 and remove int a
for(int i = 0; i < [data length]; i += 4)
{
int r = i;
int g = i+1;
int b = i+2;
int a = i+3;
pixels[r] = pixels[r]; // eg. remove red
pixels[g] = pixels[g];
pixels[b] = pixels[b];
pixels[a] = pixels[a];
}
// create a new image from the modified pixel data
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
size_t bitsPerPixel = CGImageGetBitsPerPixel(imageRef);
size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, [data length], NULL);
CGImageRef newImageRef = CGImageCreate (
width,
height,
bitsPerComponent,
bitsPerPixel,
bytesPerRow,
colorspace,
bitmapInfo,
provider,
NULL,
false,
kCGRenderingIntentDefault
// the modified image
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
imgView.image = newImage;
我也尝试过从这段代码中拉伸图像。
UIImage *stretchImage = [image stretchableImageWithLeftCapWidth:10 topCapHeight:10];
有谁能够帮助我?我没有找到任何可以为我提供这种功能的框架或 SDK。我已经用谷歌搜索了很长时间。