我有两张需要相互叠加的图像,它们都是 png 图像(因为我需要能够使它们透明)。但是,当我将它们加载到我的 xib 文件中的 UIImage 视图中时,它们都不会显示!当我尝试使用相同图像的 jpg 格式时,它可以正常工作,但是因为 jpg 不支持透明度,所以我需要的叠加效果丢失了。如何让 png 图像实际显示在窗口中?
问问题
3885 次
2 回答
4
这是一种从代码中比从接口“Crappy”生成器更容易完成的任务:
CGRect imageFrame = CGRectMake(x, y, width, height);
UIImage *image1 = // however you obtain your 1st image
UIImage *image2 = // however you obtain your 2nd image
UIImageView *imgView1 = [[UIImageView alloc] initWithImage:image1];
// Adjust the alpha of the view
imgView1.alpha = 1.0f; // This is most advisably 1.0 (always)
imgView1.backgroundColor = [UIColor clearColor];
imgView1.frame = imageFrame;
UIImageView *imgView2 = [[UIImageView alloc] initWithImage:image2];
// Adjust the alpha of the view
imgView1.alpha = 0.5f; // or whatever you find practical
imgView1.backgroundColor = [UIColor clearColor];
imgView2.frame = imageFrame;
// Assume a view controller
[self.view addSubview:imgView1];
[self.view addSUbview:imgView2]; // add the image view later which you wanna be on the top of the other one
// If non-ARC environment, we need to take care of the percious RAM
[imgView1 release];
[imgView2 release];
于 2012-07-18T19:26:19.090 回答
1
尝试在 photoshop 或 pixelmator 等照片编辑器中打开您的 png 图像,然后将其再次保存为非隔行扫描(在 png 的保存选项中)。
于 2012-07-18T19:31:40.023 回答