0
 //This method Launches the picker to take the picture from camera. 
-(IBAction)takeyouphoto:(id)sender
{
     if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            // Create image picker controller

            UIImagePickerController *imagePicker2 = [[UIImagePickerController alloc] init];

            // Set source to the camera
            imagePicker2.sourceType =  UIImagePickerControllerSourceTypeCamera;

            // Delegate is self
            imagePicker2.delegate = self;
            // Allow editing of image ?
            imagePicker2.allowsEditing= NO;

            // Show image picker
            [self presentModalViewController:imagePicker2 animated:YES];

        }
}
//This is ImagePicker Delegate method. 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
 @try {
        NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
 if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
        {
            UIImage *resultimage=nil;
            //I am using iOS5, so we can not use NSAutoreleasePool
             resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;

            //This Launches the HUD (Activity Indicator) because ImagePicker ususally takes 5  
             //seconds to launch image.
            [self showHUD:resultimage];
         }
    }
       [picker dismissModalViewControllerAnimated:YES];
}
-(void)showHUD:(UIImage *)resultimage
{
    [[Singleton sharedmysingleton] stoptimer];
    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];

    HUD.delegate = self;
    HUD.labelText = @"Loading Image";
    //HUD.detailsLabelText=@"Loading";
    //Below call on showWhileExecuting of the MBProgressHuD class has its own NSAutoreleasePool
    //Defined in MGProgressHUD class. it also runs the method showimageincell; in separate 
    //thread.

    [HUD showWhileExecuting:@selector(showimagesincell:) onTarget:self withObject:resultimage animated:YES];

}
-(void)showimagesincell:(UIImage *)image
{

    appDelegate.tabbarcontroller.tabBar.userInteractionEnabled=NO;
    NSError *error;

     UIImage *resultImage=[self scale:image toSize:image.size];

    //UIImage *resultImage = [[UIImage alloc] initWithCGImage:imgRefCrop scale:1.0 orientation:resultimage.imageOrientation];

    //resultimage.imageOrientation
    NSData *imagedata=UIImageJPEGRepresentation(resultImage, 0.7);//(resultImage);



    UIImage *smallimage=[self scale:image toSize:CGSizeMake(100, 100)];
    NSData *smallimagedata=UIImageJPEGRepresentation(smallimage, 0.7);

    /* NSString *imagetypeid=[Fetchsavefromcoredata getImagenameandImageidfromdatabase:@"Mobile_ImageType" attributename:@"imageType" predicate:imagetypetxtfield.text];

     //write image to document directory
     NSString *localImagedir=[photodirpath stringByAppendingPathComponent:selectedvinnumber];
     NSString *datetime=[Singleton imagedateandtime];
     NSString *imagename=[NSString stringWithFormat:@"%@_%@.png",imagetypeid,datetime];
     NSString *localImagePath=[localImagedir stringByAppendingPathComponent:imagename];
     [imagedata writeToFile:localImagePath atomically:YES];*/

    [self performSelectorOnMainThread:@selector(updatetableview) withObject:nil waitUntilDone:NO];
}

-(void)updatetableview
{
    [[Singleton sharedmysingleton] starttimer];
    [self viewWillAppear:YES];
}


-(UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}


//Above is all my code, I have tried to find it on diffrent forums but I have not fixed it yet.  
//Any help will be appreciated. Thanks in advance 
4

1 に答える 1

0

ホワイトスクリーンの問題は、UIIMagePickerControllerデリゲートメソッドによって返された画像を@autoreleasepool(iOS5の場合)に保持することで修正されています。問題は解決しました。ARCコードでNSAutoreleasePoolを使用することはできません。

ここに、didFinishPickingMediaWithInfoのコード行があります:デリゲートメソッド

UIImage *resultimage=nil;
@autoreleasepool
{
          //I am using iOS5, so we can not use NSAutoreleasePool
         resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;

}

@autoreleasepoolを実装した後のUIImagePickerControllerデリゲートメソッドの下

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
 @try {
        NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
 if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
        {
            UIImage *resultimage=nil;
            @autoreleasepool
           {
              //I am using iOS5, so we can not use NSAutoreleasePool
              resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;
           }

            //This Launches the HUD (Activity Indicator) because ImagePicker ususally takes 5  
             //seconds to launch image.
            [self showHUD:resultimage];
         }
    }
       [picker dismissModalViewControllerAnimated:YES];
}
于 2012-07-19T07:36:47.590 に答える