-2

I am getting an image from gallery and displaying it in the collectionViewCell. When user clicks the collectionViewCell that image is dimply into anotherView. I have tableView which is having filters (Effects) to apply when I click tableViewCell. But here I am getting exception. My code is

- (void)viewDidLoad
{
    self.imageView.image = inputImage11;
    self.secImgView.image = secblurImage;

    arrEffects = [[NSMutableArray alloc] initWithObjects:
        [NSDictionary dictionaryWithObjectsAndKeys:@"Original", @"title", @"", @"method", nil],
        [NSDictionary dictionaryWithObjectsAndKeys:@"Brightness", @"title", @"e1", @"method", nil],
        [NSDictionary dictionaryWithObjectsAndKeys:@"BoardWalk", @"title", @"e2", @"method", nil], nil
    ];
    //here getting this Exception
    thumbImage = [inputImage11 scaleToSize:CGSizeMake(300.0f, 300.0f)];
    minithumbImage = [thumbImage scaleToSize:CGSizeMake(40, 40)];
}   

I tried googling the issue but have not found a solution. Can anybody please suggest a solution. Thank you in advance.

Mika
  • 5,807
  • 6
  • 38
  • 83
vani lucky
  • 191
  • 10

1 Answers1

0

Just replace your line with the following:

thumbImage = [self imageWithImage:inputImage11 scaleToSize:CGSizeMake(300.0f, 300.0f)];

And add this method to your class:

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    // In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
    // Pass 1.0 to force exact pixel size.
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}

Credit: @Paul Lynch for the method.

Also, these are some categories you should look at: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

Mika
  • 5,807
  • 6
  • 38
  • 83
  • getting error like NO visible @interface secondViewController declares the selector imageWithImage:scaleToSize:' – vani lucky Mar 19 '15 at 05:23
  • You need to put the method in the same view controller where you are calling it. If not you need to create a helper class. – Mika Mar 19 '15 at 09:50
  • i want to call this method in same viewController..actaully my requirement is i have an image in viewController which having tableView also so when we click tableviewCell we want to apply filter effect to image..similarly when i click another tableviewcell some other filter effect will be applied .. – vani lucky Mar 19 '15 at 10:01
  • Dude there is nothing in your code above about filters. You asked about scaling to fit and I showed you how to do that. – Mika Mar 19 '15 at 11:30