目前,尝试通过 URL 下载图像并以 Apple 商店的 PhotoScroller 应用程序的方式平铺这些图像。最大图像尺寸为 4000 * 4000,为 RGB 格式。我正在使用 256 * 256 的 tilesize 平铺这些图像。平铺图像并将文件写入磁盘需要很长时间。如果可以平铺文件并在 iphone 上加载,则正在寻找更好的方法。总共 4 个 URL 调用,每个 URL 调用获取图像并通过平铺过程并调用 PhotoScroller 应用程序以在 iphone 上启动这些图像。
如果有人遇到过此类问题并对此有所了解,您能否分享一些想法。
-(void) startImageDownloading
{
if (!isImageRequested)
{
isImageRequested = YES;
self.responseData = [NSMutableData data];
URL1 = @"http://www.abc.com/image_id=1&size=1";
NSURLRequest *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:URL1]];
self.connection1= [[[NSURLConnection alloc] initWithRequest:request1 delegate:self] autorelease];
URL2 = @"http://www.abc.com/image_id=2&size=2";
NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:URL2]];
self.connection2= [[[NSURLConnection alloc] initWithRequest:request2 delegate:self] autorelease];
URL3 = @"http://www.abc.com/image_id=3&size=3";
NSURLRequest *request3 = [NSURLRequest requestWithURL:[NSURL URLWithString:URL3]];
self.connection3= [[[NSURLConnection alloc] initWithRequest:request3 delegate:self] autorelease];
URL4 = @"http://www.abc.com/image_id=4&size=4";
NSURLRequest *request4 = [NSURLRequest requestWithURL:[NSURL URLWithString:URL4]];
self.connection4= [[[NSURLConnection alloc] initWithRequest:request4 delegate:self] autorelease];
}
}
- (void)saveTilesOfSize:(CGSize)size
forImage:(UIImage*)image
toDirectory:(NSString*)directoryPath
usingPrefix:(NSString*)prefix
{
CGFloat cols = [image size].width / size.width;
CGFloat rows = [image size].height / size.height;
int fullColumns = floorf(cols);
int fullRows = floorf(rows);
CGFloat remainderWidth = [image size].width - (fullColumns * size.width);
CGFloat remainderHeight = [image size].height - (fullRows * size.height);
if (cols > fullColumns) fullColumns++;
if (rows > fullRows) fullRows++;
CGImageRef fullImage = [image CGImage];
for (int y = 0; y < fullRows; ++y) {
for (int x = 0; x < fullColumns; ++x) {
CGSize tileSize = size;
if (x + 1 == fullColumns && remainderWidth > 0) {
// Last column
tileSize.width = remainderWidth;
}
if (y + 1 == fullRows && remainderHeight > 0) {
// Last row
tileSize.height = remainderHeight;
}
CGImageRef tileImage = CGImageCreateWithImageInRect(fullImage,(CGRect){{x*size.width, y*size.height},tileSize});
NSData *imageData = UIImagePNGRepresentation([UIImage imageWithCGImage:tileImage]);
CGImageRelease(tileImage);
NSString *path = [NSString stringWithFormat:@"%@/%@%d_%d.png",directoryPath, prefix, x, y];
[imageData writeToFile:path atomically:NO];
}
}
}