Iphone 在iOS中将两个uiimageview合并为一个uiimageview
我发现下面给出了合并两个图像的代码,如果任何一个有另一个代码,请将这两个图像合并为一个图像 当我将两个uiimageview合并为一个uiimageview时,最终的图像会变成黑色或白色。。最终图像中未出现遮罩图像的实际颜色Iphone 在iOS中将两个uiimageview合并为一个uiimageview,iphone,objective-c,ipad,xcode4.5,Iphone,Objective C,Ipad,Xcode4.5,我发现下面给出了合并两个图像的代码,如果任何一个有另一个代码,请将这两个图像合并为一个图像 当我将两个uiimageview合并为一个uiimageview时,最终的图像会变成黑色或白色。。最终图像中未出现遮罩图像的实际颜色 开发人员文档说明: 面具。如果遮罩是图像,则必须为设备灰色 空间,不能有alpha分量,并且本身不能被屏蔽 通过图像遮罩或遮罩颜色。如果遮罩的大小不同 作为image参数指定的图像,Quartz将缩放 遮罩以适合图像 与例如Photoshop不同,CoreGraphics
开发人员文档说明: 面具。如果遮罩是图像,则必须为设备灰色 空间,不能有alpha分量,并且本身不能被屏蔽 通过图像遮罩或遮罩颜色。如果遮罩的大小不同 作为image参数指定的图像,Quartz将缩放 遮罩以适合图像
与例如Photoshop不同,CoreGraphics不允许掩蔽波谷alpha通道,而是允许波谷灰度。你确定你的面具是灰度的吗?开发者文档说明: 面具。如果遮罩是图像,则必须为设备灰色 空间,不能有alpha分量,并且本身不能被屏蔽 通过图像遮罩或遮罩颜色。如果遮罩的大小不同 作为image参数指定的图像,Quartz将缩放 遮罩以适合图像 与例如Photoshop不同,CoreGraphics不允许掩蔽波谷alpha通道,而是允许波谷灰度。你确定你的面具是灰度的吗?嗨,试试这个
UIImage* bottomImage = [UIImage imageNamed:@"index.jpg"];
UIImage* topImage = [UIImage imageNamed:@"tiger.png"];
UIImageView* imageView = [[UIImageView alloc] initWithImage:bottomImage];
UIImageView* subView = [[UIImageView alloc] initWithImage:topImage];
[imageView addSubview:subView];
UIGraphicsBeginImageContext(imageView.frame.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeMultiply);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* blendedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[subView release];
[imageView release];
self.resultImage.image=blendedImage; //Your Image set
您的问题的最终修改方法:-
我希望这个方法能解决你的问题。…嗨,试试这个
UIImage* bottomImage = [UIImage imageNamed:@"index.jpg"];
UIImage* topImage = [UIImage imageNamed:@"tiger.png"];
UIImageView* imageView = [[UIImageView alloc] initWithImage:bottomImage];
UIImageView* subView = [[UIImageView alloc] initWithImage:topImage];
[imageView addSubview:subView];
UIGraphicsBeginImageContext(imageView.frame.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeMultiply);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* blendedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[subView release];
[imageView release];
self.resultImage.image=blendedImage; //Your Image set
您的问题的最终修改方法:-
我希望这个方法能解决你的问题….将你所有的图像放在一个视图中,并调用这个方法,它会合并所有的图像并生成新的图像
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
将所有图像放在一个视图中并调用此方法,它会合并所有图像并生成新图像
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
我没有为你编写的代码,但据我所知,你必须用它自己遮掩火焰图像,然后将其与美丽的图像合并。我没有为你编写的代码,但据我所知,你必须用它自己遮掩火焰图像,然后将其与美丽的图像合并。试试这个
UIImage *image1 = [UIImage imageNamed:@"image1.png"];
UIImage *image2 = [UIImage imageNamed:@"image2.png"];
CGSize size = CGSizeMake(image1.size.width, image1.size.height);
UIGraphicsBeginImageContext(size);
[image1 drawInRect:CGRectMake(0,0,size.width, image1.size.height)];
[image2 drawInRect:CGRectMake(0,0,size.width, image2.size.height)];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Add image to view
imageView.image = finalImage;
试试这个
UIImage *image1 = [UIImage imageNamed:@"image1.png"];
UIImage *image2 = [UIImage imageNamed:@"image2.png"];
CGSize size = CGSizeMake(image1.size.width, image1.size.height);
UIGraphicsBeginImageContext(size);
[image1 drawInRect:CGRectMake(0,0,size.width, image1.size.height)];
[image2 drawInRect:CGRectMake(0,0,size.width, image2.size.height)];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Add image to view
imageView.image = finalImage;
介意发布一些合适的图片吗?我们中的一些人可能在办公室。看看我的答案。。。只需捕获该视图并保存在您的library@kagmanoj你试试我的答案??介意贴一些合适的图片吗?我们中的一些人可能在办公室。看看我的答案。。。只需捕获该视图并保存在您的library@kagmanoj你试试我的答案??如果你遇到任何困难,请告诉我,不要发布像上面这样的图片。。。可能是一些人可能不会回答你的问题这是工作,但底部图像没有出现,如果它合并,那么合并颜色将改变,这是我的问题让我知道,如果你面临任何困难,不要张贴像上面这样的图像。。。可能有些人可能不会回答你的问题这是工作,但底部图像不会出现,如果它合并,那么合并颜色会改变,这是我的问题,你说的把所有图像放在一个视图中是什么意思。我们是否将UIImageView添加为子视图?是的,您需要将图像放入UIView并调用此方法来创建图像。将所有图像放入一个视图是什么意思。我们是否将UIImageView添加为子视图?是的,您需要将图像放入UIView并调用此方法来创建图像。