Coder Social home page Coder Social logo

Comments (3)

rivera-ernesto avatar rivera-ernesto commented on June 19, 2024

Does it happen with the demo app?

More generally, you may be doing some picture processing in the main thread, try using Grand Dispatch Central to do it in other threads with lower priority.

from ios-nbuimagepicker.

aseemsandhu avatar aseemsandhu commented on June 19, 2024

I was not able to get down to the bottom of what seems like a deadlock. I am doing some image processing on the main thread. Here is my code:

[NBUImagePickerController startPickerWithTarget:self options:options customStoryboard:nil resultBlock:^(NSArray *imagesOrMediaInfos) {

    id mediaObject = [imagesOrMediaInfos firstObject];
    if ([mediaObject isKindOfClass:[UIImage class]]) {

        UIImage *image = (UIImage *)mediaObject;
        UIImage *transformedImage = [image transformToSquareImage];

        [self.btnSelectPhoto setImage:nil forState:UIControlStateNormal];

        self.imageView.image = transformedImage;

        self.pngData = UIImageJPEGRepresentation(transformedImage, 0.9);
    }
}];

And here is the method in my UIImage category:

- (UIImage *)transformToSquareImage {

     float currentImageWidth = self.size.width;
     float currentImageHeight = self.size.height;

     float diff = currentImageWidth - currentImageHeight;

     if (diff == 0) {
         return self;
     }

     CGSize desiredSize = CGSizeMake(MAX(currentImageWidth, currentImageHeight), MAX(currentImageWidth, currentImageHeight));

     UIGraphicsBeginImageContext(desiredSize);

     UIImage *image1;
     UIImage *image2;

     if (diff > 0) {

         // Width is greater than the height
         image1 = [OCCommon createImageWithColor:[UIColor blackColor] size:CGSizeMake(currentImageWidth, diff / 2)];
         image2 = [OCCommon createImageWithColor:[UIColor blackColor] size:CGSizeMake(currentImageWidth, diff / 2)];
         [image1 drawInRect:CGRectMake(0 ,0, image1.size.width, image1.size.height)];
         [self drawInRect:CGRectMake(0, image1.size.height, currentImageWidth, currentImageHeight)];
         [image2 drawInRect:CGRectMake(0, image1.size.height + currentImageHeight, image2.size.width, image2.size.height)];

     } else if (diff < 0) {

         // Height is greater than the width
         image1 = [OCCommon createImageWithColor:[UIColor blackColor] size:CGSizeMake(-diff / 2, currentImageHeight)];
         image2 = [OCCommon createImageWithColor:[UIColor blackColor] size:CGSizeMake(-diff / 2, currentImageHeight)];
         [image1 drawInRect:CGRectMake(0 ,0, image1.size.width, image1.size.height)];
         [self drawInRect:CGRectMake(image1.size.width, 0, currentImageWidth, currentImageHeight)];
         [image2 drawInRect:CGRectMake(image1.size.width + currentImageWidth, 0, image2.size.width, image2.size.height)];

     }

     UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();

     UIGraphicsEndImageContext();

     return finalImage;
}

With this code, I would assume that the main thread would only temporarily be blocked until the processing is finished. Am I missing something?

from ios-nbuimagepicker.

rivera-ernesto avatar rivera-ernesto commented on June 19, 2024

Yes, it should "just" temporarily freeze your app, which isn't good, but shouldn't stop the app altogether.

Try debugging in Xcode by hitting pause when your app gets frozen. Then check the stack trace to see what it was doing.

2015-07-21 9 17 35

As for the picker, once it calls your resultBlock it is dismissed and shouldn't be doing anything else. In other words, I'm pretty sure it's on your side.

from ios-nbuimagepicker.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.