程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-將兩張圖片重疊後顯示為新圖片

ios-將兩張圖片重疊後顯示為新圖片

編輯:編程綜合問答
將兩張圖片重疊後顯示為新圖片

想要實現兩張圖片重疊後顯示為新突破,但是運行後模擬器什麼也沒顯示

代碼如下:

- (void)viewDidLoad
{
    [super viewDidLoad];

    image1 = [[UIImage alloc]init];

    image1 = [UIImage imageNamed:@"iphone.png"];

    imageA = [[UIImageView alloc]initWithImage:image1];


    [self merge];

}

-(void)merge
{
  CGSize size = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(size);

    CGPoint thumbPoint = CGPointMake(0,0);
    imageview.image = imageA.image;
    [imageA.image drawAtPoint:thumbPoint];

    imageB = [[UIImage alloc]init];

    imageB = [UIImage imageNamed:@"Favorites.png"];

    CGPoint starredPoint = CGPointMake(0, 0);
    [imageB drawAtPoint:starredPoint];

    UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageview.image = imageC;

    [self.view addSubview:imageview];

}

請高手指點,問題出在哪了?謝謝

最佳回答:


把你所有地方merge裡面的代碼換成下面的:

-(void)merge
{
    CGSize size = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(size);

    CGPoint point1 = CGPointMake(0,0);
   //兩張圖像必須有不同點,不然看不來是重疊
    CGPoint point2 = CGPointMake(100,100);

    UIImage *imageOne = [UIImage imageNamed:@"Image1.png"];
    [imageOne drawAtPoint:point1];



    UIImage *imageTwo = [UIImage imageNamed:@"Image2.png"];
  // 如果需要兩張圖片混搭,可以添加類似如下代碼
  //  [imageTwo drawAtPoint:point2 blendMode:kCGBlendModeMultiply alpha:0.5];

    [imageTwo drawAtPoint:point2];


    UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(100,100,200,200)];
    iv.image=imageC;

    [self.view addSubview:iv];


}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved