Cropping images

Is there any plan to add image manipulation to Corona?

In particular I need to be able to display an image, show some crop corners and allow the user to crop the image.

I realize you can change the w, h of an image which does crop it, but ONLY from the center of the image. I need to be able to crop an arbitrary rectangle.

Another option would be to add x,y,w,h to the display.save() function.

Giving us simple getPixel(), setPixel() functions would also work.

I’ve seen people request these features for over half a year, and no response from Ansca. Can someone from Ansca please weigh in on this? [import]uid: 16734 topic_id: 21173 reply_id: 321173[/import]

You will get a lot of +1’s on this. I need to ignore transparency on collisions which is kind of the same vein.

I think now that we got so much new stuff in December that perhaps, we need a new Roadmap.

[import]uid: 19626 topic_id: 21173 reply_id: 83843[/import]

you can probably cater for every size if you want to crop by using masks, which you will have to stretch, squish to the size you want as you cannot create dynamic masks in Corona.

In OpenGL there is a simple clipping path that can be enabled but for some reason it is not ans we have to use these masks, etc, whatever.

There is also the GL_SCISSOR that can allow for creating viewports but we do not have that.

I guess we might never get getPixel and setPixel for Corona, thought they are the most fundamental in graphics generation.
[import]uid: 3826 topic_id: 21173 reply_id: 83870[/import]

@JayantV,

Masks don’t work properly if you scale the image.

Let’s say I let the user define a rectangle for cropping. I create a mask for that. Works fine. Now I scale my image up so the cropped portion fits the width or height of the display. What happens to the mask? Does it work? I believe in tests I did a couple of months ago it does NOT work.

Corona is good for certain types of Apps, but until they add some additional features like bitmap manipulation it won’t ever become a solution that can compete with someone writing in Obj-C. That may sound unfair, but I believe it’s true. [import]uid: 16734 topic_id: 21173 reply_id: 83871[/import]

@Ken, I agree with you, I was just suggesting what officially the forum warden would tell you, “Use Masks and get on with it…” If we could create dynamic masks, it would be helpful.

I guess what you are saying is the same that a lot of people are feeling around, as one user put it rather interestingly on the forum http://developer.anscamobile.com/forum/2012/01/31/there-any-plan-update-physics-near-future

If mobile applications is the future, and more features are not added, this will start to become another GS or a toy framework and the warden will feel right at home. [import]uid: 3826 topic_id: 21173 reply_id: 83873[/import]

There are still a lot of things you can do with Corona, so I’m not saying it’s not usable. Just that if you want to push the edge a bit, or do certain things, it just doesn’t work.

Exposing access to textures, making copies of textures, etc. is such a basic thing in game development I am surprised it wasn’t part of Corona 1.0.

Unfortunately, my next few projects require more than Corona offers, so I will be forced to stop using it (and stop supporting the community with code solutions, help, etc) if I don’t have the functionality I need.

This is not going to change anything for Ansca; they have their own business plan and have done exceedingly well with it so far. However, I agree with you, they will soon become more of a “demo” type platform than a viable mobile solution if they don’t address some of these issues.

I would gladly offer (and have in the past), my technical expertise to help them implement anything on their road map. So far, they haven’t taken me up on my offer. [import]uid: 16734 topic_id: 21173 reply_id: 83876[/import]

:slight_smile:

That’s all I can say. You have been here long enough to see things, I used to be the Ambassador Program Manager, their *Developer Evangelist* I had close access to a lot of stuff, but…

Good luck on holding your breath for them to take up your offer. You need to know the whole tree for yourself.
[import]uid: 3826 topic_id: 21173 reply_id: 83877[/import]

@JayantV,

I’m not holding my breath at all. If I can use Corona and it makes sense to do so I will continue to use it. But when I can no longer use it I will move on.

Development tools and SDK’s are an investment in time. Once you bite the bullet and learn a SDK well enough to ship a title there is not much reason to change to another SDK; unless that SDK no longer meets your needs.

Any GOOD, ROBUST SDK allows the user to extend it. Unfortunately, Corona is NOT extensible with regard to anything missing that requires system (iOS or Android) access.

This is the one problem with Corona that almost caused me not to use it for my first iOS/Android title. My second title will be coming out soon and Corona was good enough for it.

However, the project after that requires features that are missing from Corona so it’s time to move to a better SDK or write my own. That’s not as hard as it sounds, I’ve written cross platform engines before. [import]uid: 16734 topic_id: 21173 reply_id: 83880[/import]

Adding getPixel and setPixel is not that easy to add to Corona at this point in time. I’ve asked the developers what it would take to add this to the openGL code and was told of a number of issues trying to implement the feature.

We understand the need for this now but it needs to be added in the proper way so it’s compatible with future feature changes in the openGL area.

It’s easy to say this and that should be added (because it’s easy to do), but the devil is in the details and it’s always a balancing act to get it implemented in the right way.

We do appreciate the input and the discussion. [import]uid: 7559 topic_id: 21173 reply_id: 84007[/import]

I suggest a much simpler solution: just add clip=true to groups, like:
local group = display.newGroup({clip=true, w=100, h=100})

Currently the display groups apply scale, alpha, rotation, x, y transforms, but you cannot set width or height. So simply adding width or height as allowed properties to enable clipping may also work.

I have used the mask workaround, but I find it to be very annoying, and I end up have lots of mask images loaded. Simple box clipping would help me position things off-screen and not have them displayed when sliding in the relevant scene. [import]uid: 73736 topic_id: 21173 reply_id: 84935[/import]

I use masks to crop images ( also scaled images). Its not pretty but it works.
Only problem is that when using display.save to save the masked group the saved image will have a frame of a few pixels around the image. If this could be fixed it would fill my cropping needs for now… [import]uid: 13632 topic_id: 21173 reply_id: 84949[/import]

+1 on the clipping group/width/height thing [import]uid: 19626 topic_id: 21173 reply_id: 84962[/import]

  • 1 Ansca please make this a priority feature. [import]uid: 94768 topic_id: 21173 reply_id: 85112[/import]

@ojnab,

Are you creating those masks dynamically?

I need to be able to allow the user to select a region on an image, then scale that up to fit the width. My experience with the masks is they do not work well on scaled images. Curious to see if you’ve had better luck with that. [import]uid: 16734 topic_id: 21173 reply_id: 85115[/import]

new crop module coming soon check it out at www.j-strahan.com [import]uid: 7911 topic_id: 21173 reply_id: 85160[/import]

there’s also a quick workaround to cropping images by using sprites and spritesheets.
every sprite is basically a “cropped image”, so you can generate spritesheet from your image on the fly and create a new sprite which will use whatever part of image you want.
it should also work much much much much faster than masking… [import]uid: 80100 topic_id: 21173 reply_id: 85204[/import]

Yes, but that only works if you want a static cropping rectangle on a single sprite. If you want to move the cropping box, you can only move on frame boundaries, or create new sprite sheets all the time. If you want to crop many sprites to fit the current viewport it does not work.

Something like the flashlight demo is pretty hard with sprite sheets.
One obvious place to apply cropping (which cannot be done with spritesheets, and is a bit hard with masks) is only displaying data inside the displayWidth and displayHeight to obtain black borders around the content for odd screen sizes. I currently do this by applying a topmost black 1px image stretched to fill it. This works, but it would be so much easier with cropping. [import]uid: 73736 topic_id: 21173 reply_id: 85207[/import]

my cropping class is working in the simulator. doing some on device testing today
it doesn’t use mask or spritesheets and you can select any portion of the screen at any size from 48x48 to full screen square or rectangle shape [import]uid: 7911 topic_id: 21173 reply_id: 85212[/import]

@kenrogoway
I’m not sure I understand you completely, but this is what I did.

I made a pinch/zoom class that also have a dragable and resizeable frame that indicates where I wan’t the image to be cropped. To crop the image I made a mask.png that is a white box with a 4 pixel black border around it. Before saving the image with display.save I apply the mask and scale + position it, so the white part of the mask has the same size as the crop-frame. Now I use display.save to save the image. It will only save the visible part, but as mentioned above it will leave a frame ( background colored ) of a few pixels around the image. I guess the extra pixels is the border from the mask.png

[edit] BTW I added the mask to a display group with the image in it… I guess this makes the difference when adding the mask to a scaled image… Not sure though!

What did you do? [import]uid: 13632 topic_id: 21173 reply_id: 85349[/import]

@ojnab,

I’ll give that a try. Obviously it is a temporary work around because of the frame around the edges, but this is better than nothing at all.

Just wish Ansca would respond to our posts. It gets frustrating not hearing anything when we point out issues like this, or the Inneractive Crash bug. [import]uid: 16734 topic_id: 21173 reply_id: 85352[/import]