Crop image?

Hi-

Is there any way to crop an image in Corona?

Apparently this is how you’d do it in objective c:

// Create the image from a png file  
UIImage \*image = [UIImage imageNamed:@"prgBinary.jpg"];  
UIImageView \*imageView = [[UIImageView alloc] initWithImage:image];  
   
// Get size of current image  
CGSize size = [image size];  
   
// Frame location in view to show original image  
[imageView setFrame:CGRectMake(0, 0, size.width, size.height)];  
[[self view] addSubview:imageView];  
[imageView release];   
   
// Create rectangle that represents a cropped image   
// from the middle of the existing image  
CGRect rect = CGRectMake(size.width / 4, size.height / 4 ,   
 (size.width / 2), (size.height / 2));  
   
// Create bitmap image from original image data,  
// using rectangle to specify desired crop area  
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);  
UIImage \*img = [UIImage imageWithCGImage:imageRef];   
CGImageRelease(imageRef);  
   
// Create and show the new image from bitmap data  
imageView = [[UIImageView alloc] initWithImage:img];  
[imageView setFrame:CGRectMake(0, 200, (size.width / 2), (size.height / 2))];  
[[self view] addSubview:imageView];  
[imageView release];  

If there’s no way to do in Corona:

  1. can the above be used in the next release of Corona?
  2. is there any way at all to call the above objective c code from within Corona?
  3. is there any workaround at all? We need to apply a circular mask to crop out a circle from a larger image

I think the Corona SDK is amazing. Our app is almost done, not being able to crop is kind of a show stopper though for this app :frowning: :frowning:

Please help.

Thanks,
John [import]uid: 14526 topic_id: 5094 reply_id: 305094[/import]

No, I don’t believe you can at present. The next release, which is due to drop, will have masking, though I don’t know if this will do what you want if you need to export the cropped image. See Carlos’ latest blog post.

m [import]uid: 8271 topic_id: 5094 reply_id: 16790[/import]

Thanks for the tip. Masking could potentially work. Looking forward to checking out the next release as always! Thanks again. [import]uid: 14526 topic_id: 5094 reply_id: 16913[/import]

Is it still the case that you cannot crop an image with corona? It would be great if we could take a picture with the camera and then crop it to resize it. It would be a shame to have to build my next app in objective C because this impossible at the moment. I really like the development speed I get from corona. [import]uid: 39480 topic_id: 5094 reply_id: 37192[/import]

Hi tim.

were you able to crop an image using corona?

I found corona a great sdk and I didn´t want to go back to objective-C.

Thanks. [import]uid: 62290 topic_id: 5094 reply_id: 37812[/import]

I’ve tried to use mask and then display.save().
It works fine.

local myImage = display.newImage(“myPhoto.JPG”,0,0)
local mask = graphics.newMask(“mymask.png”)
myImage:setMask(mask)
display.save(myImage,“myImage.jpg”)

By this way, you need to prepare a well sized image mask use to “crop” the image. I hope it helps! [import]uid: 24984 topic_id: 5094 reply_id: 45364[/import]