Forums » C++ Framework » How to convert UIImage to CCSprite? »
| Jung Jun Lee | How to convert UIImage to CCSprite? | ||||
|---|---|---|---|---|---|
|
Added by Jung Jun Lee over 1 year ago
Hi everyone. I want to bring the image from the Internet in app. So... UIImage* img = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl]]; But, I don't know convert UIImage to CCSPrite. |
||||
| Zhe Wang | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Zhe Wang over 1 year ago
The sequence is:
Enjoy Coding, Enjoy Life. |
||||
| Jung Jun Lee | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Jung Jun Lee over 1 year ago
sorry |
||||
| Jung Jun Lee | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Jung Jun Lee over 1 year ago
Walzer Wang wrote: The sequence is: I am sorry. How to get pData and nDataLength? Please, you write in detail about subject. |
||||
| Zhe Wang | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Zhe Wang over 1 year ago
I think you can get the image row data from UIImage.CGImage property. Enjoy Coding, Enjoy Life. |
||||
| Jason M | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Jason M about 1 year ago
CCImage::initWithImageData is looking for a CCData object as the first param, but CCData is not fully implemented. You can only create a CCData by using dataWithContentsOfFile. As far as I can tell, you'd have to load in the UIImage data as NSData, save that as a file, then create a CCData from that saved file. I'm I getting this right? //@todo implement |
||||
| Jason M | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Jason M about 1 year ago
Figured out a work around. Once you load it, save the image to the local device. You can use CCSprite::spriteWithFileName to load it back in. NSData *fileData = [YOUR IMAGE DATA]; Then later... Only way I could load in external images. CCData does not work with NSData. |
||||
| Emmy Chen | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Emmy Chen about 1 year ago
How do you get images from URL and save them to the local disk on Android? Your method is for iOS only. It is not portable. I am looking for android solution. |
||||
| Oren Bengigi | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Oren Bengigi 11 months ago
If anyone interested, I've done it using the following ugly hack: @ // Your code struct Hack
{
// CCImage.h // For IOS // CCImage_ios.mm struct Hack
{ bool CCImage::initWithUiImage(void* hackPtr)
{
@ Super ugly, but works Checkout my game: |
||||
| Anthony Bongers | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Anthony Bongers 11 months ago
I'm a bit late to the party, but here's a solution I used.
Enjoy! |
||||
| Mike M | RE: How to convert UIImage to CCSprite? | ||||
|
Anthony This has been working good for me in most cases. I am taking the picture obtained from the camera and using that in my program. I am testing on some older devices iPh4 & 3GS and if I take a picture using the normal backside camera the image is black. If i use the front facing camera it works as expected. Also on newer devices iPh5, iPad 2, 3, Mini both work as expected. Any ideas why I would be receiving a black image once its back in cocos2dx on older devices? |
||||
| Anthony Bongers | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Anthony Bongers 3 months ago
Mike M wrote:
I can't say for certain since I haven't captured data from the camera to display in cocos2d before. My first guess would be that older devices may have different formats. Maybe the bytes per pixel is 3 on older devices instead of 4 on newer devices. |
||||
| Anthony Bongers | RE: How to convert UIImage to CCSprite? | ||||
|
Added by Anthony Bongers 3 months ago
Mike M wrote:
I can't say for certain since I haven't captured data from the camera to display in cocos2d before. My first guess would be that older devices may have different formats. Maybe the bytes per pixel is 3 on older devices instead of 4 on newer devices. |
||||
| Mike M | RE: How to convert UIImage to CCSprite? | ||||
|
Thanks for the reply, I actually just 2 minutes ago figured out what was going on and it was rather simple fix. It seems the image being taken was 1936x2592 way larger then would ever be needed on an iPhone for my purposes. So I simply scaled the CGImage and then used that and it all worked fine now. |
(1-13/13)
