如何解决将设备更改为ipad视网膜时的Exe访问错误

时间:2013-03-14 10:09:30

标签: iphone ios objective-c ipad uiimage

我们正在开发ipad应用程序,我正在通过此代码比较两个图像:

-(BOOL) compareTwoImages:(UIImage *) firstImage SecondImage:(UIImage *) secondImage
{

    int count=0;
    int match=0;
    int mismatch=0;

    //  UIColor* color = nil;
    CGImageRef inImage = [firstImage CGImage];
    CGImageRef outImage =[secondImage CGImage];

    // Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
    CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];//this method creates context

    CGContextRef cgctx1 = [self createARGBBitmapContextFromImage:outImage];
    if (cgctx == NULL) { return NO; /* error */ }
    else if (cgctx1 == NULL) { return NO; /* error */ }

    size_t w = CGImageGetWidth(inImage);
    size_t h = CGImageGetHeight(inImage);
    CGRect rect = {{0,0},{w,h}};

    // Draw the image to the bitmap context. Once we draw, the memory
    // allocated for the context for rendering will then contain the
    // raw image data in the specified color space.

    CGContextFlush(cgctx);
    CGContextFlush(cgctx1);


    CGContextDrawImage(cgctx, rect, inImage);
    CGContextDrawImage(cgctx1, rect, outImage);


    CGContextFlush(cgctx);
    CGContextFlush(cgctx1);

    CGContextFlush(cgctx);
    CGContextFlush(cgctx1);



    // Now we can get a pointer to the image data associated with the bitmap
    // context.
    unsigned char* data = CGBitmapContextGetData (cgctx);
    unsigned char* data1 = CGBitmapContextGetData (cgctx1);


    if ((data != NULL)&&(data1 != NULL))
    {
        //offset locates the pixel in the data from x,y.
        //4 for 4 bytes of data per pixel, w is width of one row of data.

        for( int yy=0;yy<h;yy++)
        {
            for (int xx=0; xx<w; xx++)
            {
                int offset = 4*((w*round(yy))+round(xx));
                int alpha =  data[offset];
                int alpha1 =  data1[offset];**//it is giving bad access here and finally crashing** 


                if( alpha >1 )
                {
                    count++;

                    if( alpha1 > 1 )
                    {
                        match++;

                    }

                }


                if( (alpha1 >1 )&& (alpha < 1))
                {

                    mismatch++;

                }


                //      NSLog(@"offset: %i colors: RGB A %i %i %i  %i",offset,red,green,blue,alpha);

            }
        }

    }

    // When finished, release the context
    CGContextRelease(cgctx);
    CGContextRelease(cgctx1);
    // Free image data memory for the context
    if (data) { free(data); }
    if (data1) { free(data1); }


    int matchPer =(int) (( (float) match/count)*100);
    int misMatchPer =(int) (( (float) mismatch/count)*100);


    NSLog(@"number of match px :%d  mismatch px :%d total count :%d  precntage %d mismathc per %d",match,mismatch,count,matchPer,misMatchPer);

    if(( matchPer>70)&&(misMatchPer <2000)) {//do anything}

当我通过此代码比较图像时它在ipad中工作正常,但是当我选择模拟器硬件&gt;&gt; ipad视网膜时会产生问题....

我试图通过intruments&gt;&gt;僵尸抓住这个糟糕的访问但却无法理解为什么它会崩溃......

1 个答案:

答案 0 :(得分:3)

只是一个想法:当应用程序已经在模拟器中运行时,您是否正在将模拟器更改为iPad Retina?如果是这种情况,您不必担心崩溃。发生这种情况是因为您突然试图停止应用程序的执行(当您更改模拟器版本时任何正在运行的应用程序退出)而不是从Xcode正确停止它。