开发者

performSelectorInBackground and performing UI Operation

In application I need to take Image out of UIView. Frame of that View is W 1800 and H 1200.

This activity takes lot time and screen stucks there unless this activity get finish.

I need to perform this activity in background,so that user can continue with other things.

What is best approach to achive this. I tried with

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg

But application get crash as it doesn't allow UI operation with this. If I go with

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait

screen stucks there unless this activity get finish.

I need to perform following activity in background

-(void) PrepareImageData
{
    UIImage* frontViewImage = [self PreparefrontImage:[self GetSavedFrontImage]];
    [self SaveImageinDocumentWithName:frontViewImage FileName:@"frontview.png"];

    UIImage* rearViewImage  = [self PrepareBackImage:[self GetSavedBackImage]];;
    [self SaveImageinDocumentWithName:rearViewImage FileName:@"backview.png"];
}
    -(UIImage*) GetSavedBackImage
    {
        UIImage* background;
        UIImage* messageTextview;
        UIImage* toTextView;
        UIImage* fromTextView;

        background      = [self GetImageFromView:self toRect:self.frame];

        CGRect rect = CGRectMake(0, 0, 1800, 1200);
        UIGraphicsBeginImageContext(rect.size);
        CGPoint backgroundPoint = CGPointMake(0,0);
        [background drawAtPoint:backgroundPoint];
        UIImage* backImage = UIGraphicsGetImageFromCurrentImageContex();
        UIGraphicsEndImageContext();

        return backImage;
    }

    - (UIImage *) GetImageFromView:(UIView *)aView toRect:(CGRect)aRect
    {
        CGSize pageSize = aRect开发者_如何学Python.size;
        UIGraphicsBeginImageContext(pageSize);
        [aView.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;

    }

Please help me on this.

Thanks.


I think your problem lies with the sheer size of the view - an app attempting to manipulate a view this size in this way is probably quite likely to get killed by the OS for using too much memory, especially under iOS 4.x. UIViews used to be limited to 1024x1024 for a very good reason.

I'd recommend looking into ways of dividing the problem up into chunks which can be processed without requiring so much memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜