Iphone,从Uiimageview获取图像数据

Iphone,从Uiimageview获取图像数据,iphone,xcode,cocos2d-iphone,Iphone,Xcode,Cocos2d Iphone,我在阵列中有5个图像,它们在UIimageview中显示,并逐个显示。我想在单击特定图像时获取图像数据,并使用触摸事件在webview中显示一些数据。我没有获取图像数据。我的代码在这里 imgarr->包括5个不同的图像 obj=[touches anyObject]; CGPoint point=[obj locationInView:self.view]; touchLocation=point; if(CGRectContainsPoint([imgview frame],point))

我在阵列中有5个图像,它们在UIimageview中显示,并逐个显示。我想在单击特定图像时获取图像数据,并使用触摸事件在webview中显示一些数据。我没有获取图像数据。我的代码在这里

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");
    }
}
obj=[接触任何对象];
CGPoint point=[obj locationInView:self.view];
接触位置=点;
if(CGRectContainsPoint([imgview帧],点))
{
//cloud.center=触摸位置;
NSData*imgData=UIImageJPEG表示法(imgview.image,9.0);
UIImage*img=[UIImage-imageWithData:imgData];
NSLog(@“selimg=%@”,img);

对于(int i=0;i如果将对象与
=
进行比较,则比较的是指针,而不是对象值

具有检查对象是否等于其自身的方法:

if ([arrdata isEqualToData:imgData]){
   NSLog(@"True");
}
试试这个

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

NSData *dataObj = UIImageJPEGRepresentation(img, 1.0);

rckoenes,感谢您的回复,控制台中也没有显示Nslog。