2012-09-17 27 views
0

目前试图访问的UIImageView一个UIImage属性来实例化另一个UIImage对象。只是我试图做到这一点。无法访问的UIImageView图像

UIImage *myImage = myExistingView.image; 

但是该属性不会设置。我不断为myImage取得零值。

我想复制的图像,最终做这样的事情

UIImageView *newImageView = [[UIImageView alloc] initWithImage:myImage]; 

,但我似乎无法得到它。建议?

编辑。最近的尝试没有奏效。

UIImageView *newView = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithData:UIImagePNGRepresentation(myImageView.image)]]; 
+2

多一点的代码可以帮助 –

+0

哪里,愿意复制图像!我看到你发布的代码没有问题...你可以测试它是否保存了这样的图像 UIImage * image = myExistingView.image; 的UIImageView * imagev = [[ALLOC的UIImageView] initWithImage:图片]; [targetimageview setImage:imagev.image]; –

+0

你在哪里/如何为myExistingView设置图像? – MikeS

回答

0

你必须初始化你的UIImage这样UIImage *myImage = [UIImage imageNamed: @"imgCheckSelected.png"];

后,您将通过MYIMAGE到newImageView。我不确定是否可以将UiImage保存在其他UIImage中。

+0

我不是试图保存另一个UIImage中的一个图像,我试图做一个图像的副本。图像已经从url加载到UIImageView中。 – StlTenny

0

做这个访问图像

UIImageView *newImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageName"]]; 

此选项将显示图像。

0

我做这个和它的作品..

UIImageView *someNewImageView = [[UIImageView alloc] initWithImage:yourExistingView.image]; 
someNewImageView.frame = CGRectMake(50, 50, 150, 150); 

[self.view addSubview:someNewImageView]; 
[someNewImageView release]; 

注意yourExistingViewUIImageView propertie在Interface Builder中添加。

你检查你的新UIImageView框架? 你设置yourExistingView图像? 你添加新的ImageView查看?