如何在UIimageview裏顯示一張圖片裏的某一部分

首先,獲取想要顯示的部分的大小及位置
CGRect rect;
然後,將此部分從圖片中剪切出來
CGImageRef imageRef=CGImageCreateWithImageInRect([image CGImage],rect);
UIImage *image1=[UIImage imageWithCGImage:imageRef];
最後,將剪切下來圖片放入UIImageView中
[imageView setImage:imgae1];


我的例子:

            NSURL *url = [NSURL URLWithString:aid];

            UIImage *myimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];

//            首先,獲取想要顯示的部分的大小及位置

            CGRect rect = CGRectMake(050320120);

//            然後,將此部分從圖片中剪切出來

            CGImageRef imageRef=CGImageCreateWithImageInRect([myimage CGImage],rect);

            UIImage *image1=[UIImage imageWithCGImage:imageRef];

//            最後,將剪切下來圖片放入UIImageView

            [imgView setImage:image1];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章