快速連結

2012年10月8日

沒有Cocos2D也能讓一張圖截取區塊去顯示

有時候希望沒了Cocos2D也能有輕鬆切圖片的功能~

雖然不夠友善,但是程式碼也不會太長的啦XD

執行結果:


下收程式碼~


圖片 test_arrows.png:



    CGRect rect = CGRectMake(0, 0, 60, 30); //先確定要切的大小
    UIImage *arrows = [UIImage imageNamed:@"test_arrows.png"];
    UIImageView *arrviewer = [[UIImageView alloc] initWithFrame:rect];
    
    [arrviewer setImage:[UIImage imageWithCGImage: CGImageCreateWithImageInRect([arrows CGImage], rect)]];
    [arrviewer setCenter:CGPointMake(45, 120)];

    [self.view addSubview:arrviewer];

沒有留言:

張貼留言

歡迎大家留言提問,我會答的都會盡力回答!
如果太久沒出現回應就是我又忘記回來看留言了TAT