29,029
社区成员
发帖
与我相关
我的任务
分享
-(void)readPicture{
UIImage *image;
switch (roleType) {
case ROLE_PLAYER:
image=[UIImage imageNamed:@"man.png"];
break;
default:
break;
}
int subImageLocationX;
if (direction.x==-1&&direction.y==0) {
subImageLocationX=0;
}else if (direction.x==1&&direction.y==0) {
subImageLocationX=IMAGE_SIZE;
}else if (direction.x==0&&direction.y==1) {
subImageLocationX=IMAGE_SIZE*2;
}else if (direction.x==0&&direction.y==-1) {
subImageLocationX=IMAGE_SIZE*3;
}else if (direction.x==-1&&direction.y==1) {
subImageLocationX=IMAGE_SIZE*4;
}else if (direction.x==1&&direction.y==-1) {
subImageLocationX=IMAGE_SIZE*5;
}else if (direction.x==1&&direction.y==1) {
subImageLocationX=IMAGE_SIZE*6;
}else if (direction.x==-1&&direction.y==-1) {
subImageLocationX=IMAGE_SIZE*7;
}
[imageArray removeAllObjects];
for (int i=0; i<14; i++) {
CGRect subImageRect=CGRectMake(subImageLocationX, i*IMAGE_SIZE, IMAGE_SIZE, IMAGE_SIZE);
CGImageRef imageRef=image.CGImage;
CGImageRef subImageRef=CGImageCreateWithImageInRect(imageRef, subImageRect);
UIGraphicsBeginImageContext(CGSizeMake(IMAGE_SIZE, IMAGE_SIZE));
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextDrawImage(context, subImageRect, subImageRef);
UIImage *subImage=[UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
[imageArray addObject:subImage];
}
[imageView setImage:[imageArray objectAtIndex:0]];
}
[imageArray addObject:subImage];
NSLog(@"subImage retainCount=%d",[subImage retainCount]);
[imageArray addObject:subImage];
[subImage release];