2012-07-09 102 views
0

我有5个图像在UIimageview中显示并逐个显示数组中的5个图像。我想获取特定图像上的图像数据点击,并显示一些数据在webview中使用触摸事件。我没有得到imagedata.My代码是在这里Iphone,从Uiimageview获取图像数据

imgarr->包括5个不同的图像

obj=[touches anyObject]; 
CGPoint point=[obj locationInView:self.view]; 
touchLocation=point; 
if(CGRectContainsPoint([imgview frame],point)) 
{ 
//cloud.center=touchLocation; 
    NSData *imgData = UIImageJPEGRepresentation(imgview.image, 9.0); 
    UIImage *img = [UIImage imageWithData:imgData]; 
    NSLog(@"selimg=%@",img); 
    for(int i=0;i<[imgarr count];i++) 
    { 
     UIImage *arr=[imgarr objectAtIndex:i]; 
     NSData *arrdata=UIImageJPEGRepresentation(arr,9.0); 
     if(arrdata==imgData) 
      NSLog(@"True"); 
    } 
} 

帮助我..

回答

1

如果你比较反对与==你是比较指针不是对象的值。

NSData有一个isEqualToData:方法来检查对象是否等于它的自我:

if ([arrdata isEqualToData:imgData]){ 
    NSLog(@"True"); 
} 
+0

rckoenes,感谢您的回复,也没有显示在控制台的NSLog 。 – user1497665 2012-07-09 13:34:24

1

试试这个

UIImage *img = [UIImage imageNamed:@"some.png"]; 

NSData *dataObj = UIImageJPEGRepresentation(img, 1.0);