繁体   English   中英

将png加载到UIImageView iOS中

[英]Loading a png into a UIImageView iOS

我有两张需要重叠的图像,它们都是png图像(因为我需要使它们透明)。 但是,当我将它们加载到xib文件中的UIImage视图中时,它们都不显示! 当我尝试使用相同图像的jpg格式时,效果很好,但是由于jpg不支持透明度,因此我失去了所需的叠加效果。 如何获得png图像以实际显示在窗口中?

界面生成器

与通过Interface“ Crappy” Builder相比,使用代码更容易执行以下任务:

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];

尝试在照片编辑器(如photoshop或pixelmator)中打开png图像,然后将其再次保存为非隔行扫描(在png的保存选项中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM