iOS-漸進(jìn)渲染大圖

漸進(jìn)渲染大圖對(duì)加載大圖特別重要,地圖都是局部加載,放大移動(dòng)時(shí)候一部分一部分的漸進(jìn)的加載,一般在對(duì)大圖進(jìn)行網(wǎng)絡(luò)請(qǐng)求時(shí)候,可以獲得一部分?jǐn)?shù)據(jù)就加載一部分?jǐn)?shù)據(jù)。

用本地圖片和定時(shí)器來(lái)模擬網(wǎng)絡(luò)加載圖片。

@interfaceViewController(){

NSMutableData* _data;

NSData* _allData;

NSUInteger length;

UIImageView* _imageView;

NSTimer* timer;

NSInteger le;

}

@end

@implementation ViewController

-(void)viewDidload{

[super viewDidload];

_data = [NSMutableData alloc]init];

NSString *path =[[NSBundlemainBundle]pathForResource:@"Portrait-ns@2x"ofType:@"png"];

_allData = [NSDatadataWithContentsOfFile:path];

length = _allData.length;

le = length/10;

timer = [NSTimer scheduledTimerWithTimeInterval:1target:self selector:@selector(updateImage) userInfo:nil repeats:YES];

_imageView = [[UIImageViewalloc]initWithFrame:self.view.frame];

[self.view addSubview:_imageView];

}

}

-(void)updateImage{

staticintindex =0;

if(index==10) {

return;

}

NSUInteger l;

if(index==9) {

l=length-le*9;

}else{

l= le;

}

Byte ?by[l];

[_allData getBytes:by range:NSMakeRange(index*le, l)];//得到新增字節(jié)然后渲染圖片。

[_data appendBytes:by length:l];

CGImageSourceRefmyImageSource =CGImageSourceCreateWithData((CFDataRef)_data,NULL);

CGImageRefmyImage =CGImageSourceCreateImageAtIndex(myImageSource,0,NULL);

CFRelease(myImageSource);

_imageView.image = [UIImageimageWithCGImage:myImage];

// ? ?image.image = [UIImage imageNamed:@"image.ico"];

index++;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容