Knightkrows.. you are just a hacker :) it is working now.. THANK YOU!
I dont have a clue what is static method.. need to study more I see...
A fast, easy to use, free, and community supported 2D game engine
Knightkrows.. you are just a hacker :) it is working now.. THANK YOU!
I dont have a clue what is static method.. need to study more I see...
All thanks to this forum buddy!!! :)
having another problem :(
using this code:
imageFromPicker = [CCSprite spriteWithCGImage:new2.CGImage key:@"ImageFromPicker"];
but it dont change picture in second picker call, when I change to
imageFromPicker = [CCSprite spriteWithCGImage:new2.CGImage key:nil];
it change the picture but later, I cannot use the changed picture because not having key:@"ImageFromPicker" to call the picture.. how to "combine" this two commands? so picker will change the picture but I will have a KEY to further work with picture...
This is my code which I am using in my one of app.
//show the image view with the picked image
UIImage *puzzleImage = (UIImage *)[info objectForKey:@"UIImagePickerControllerOriginalImage"];
CGSize size = [puzzleImage size];
puzzleImage = [CCImageUtilities image:puzzleImage fillSize:CGSizeMake(CANVAS_WIDTH, CANVAS_HEIGHT)];
[puzzleImage retain]; //try this line
puzzleSprite = [CCSprite spriteWithCGImage:[puzzleImage CGImage] key:nil];
[self addChild:puzzleSprite];
try this line '[puzzleImage retain];' and let me know.
Thanks,
hi Knightkrows, thank you again for your fast answer, I will try your code, anyway, my function what I call in other place in HelloWorldScene.mm is using sprite defined by KEY, and in your code, there is no KEY so.. it wouldnt work for me.. or how to assing sprite into new sprite without key? is it possible?
my code:
Effect1Sprite *effect1sprite = [EffectSprite effectWithSprite:[CCSprite spriteWithFile:@"ImageFromPicker" ] func1:10 func2:50];
so.. as you can see, i use spriteWithFile:@"ImageFromPicker" so I need to have key defined, key:nil is not working for me, or is there any other way to use sprite?
I had to use key value as nil, as I don't want to fetch it from CCTextureCache and moreover I had to create a mechanism for a new key Value to generate for some reason.
that is exactly what I was thinking about..
make something:
int number;
and then:
number++;
puzzleSprite = [CCSprite spriteWithCGImage:[puzzleImage CGImage] key:@"number"];
edit: NSString I will use.. let you know...
but what is the syntax?
@"%d",i ? I must try ...
You can try for timestamp.
like:
NSString *key = [NSString stringWithFormat:@"%.0f.png",CFAbsoluteTimeGetCurrent()];
no.. doesnt work.. I dont understand WHY??? our solution is changing key for every time that picker choice a new photo..
so there is a new key for every round...
can you paste your code that you are using inside
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
Thanks,
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{
klucCislo2++;
keykluc2 = [NSString stringWithFormat:@"%d",klucCislo2];
// newImage is a UIImage do not try to use a UIImageView
newImage22 = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// newImage22 = [info objectForKey:keykluc2];
// Dismiss UIImagePickerController and release it
[picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
[picker release];
// Let's create a sprite now that we have an image
UIImage *newImage22 = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// UIImage *newImage22 = [info objectForKey:keykluc2];
UIImage *new2 = [HelloWorldLayer scaleImage:newImage22 toSize:CGSizeMake(320,480)];
klucCislo++;
keykluc = [NSString stringWithFormat:@"%d",klucCislo];
// keykluc = [[NSString alloc] initWithFormat: @"%i",klucCislo];
// [keykluc initWithFormat:@"%i",klucCislo];
// NSString *key = [NSString stringWithFormat:@"%.0f.png",CFAbsoluteTimeGetCurrent()];
//CCSprite *imageFromPicker = [CCSprite spriteWithCGImage:newImage.CGImage key:@"ImageFromPicker"];
CCSprite *imageFromPicker = [CCSprite spriteWithCGImage:new2.CGImage key:keykluc];
stav = 2;
imageFromPicker.position = ccp(160, 240);
[self addChild:imageFromPicker z:1 tag:98];
}can you tell me once again, what actually the problem is?
:) the problem is that I choose picture, then is picture shown, and doing some stuff with picture, but then AGAIN I select picture from imageGallery but.. the old one is presented..
when I change to
CCSprite *imageFromPicker = [CCSprite spriteWithCGImage:new2.CGImage key:nil]; <--nil is on the end
it change the picture right way, BUT I dont know how to work with picture because I have NO key defined..
and when using "dynamical" key++, it gives SIGABRT...
Uh, in that code snippet, you have a scoping issue:
newImage22 = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[...]
UIImage *newImage22 = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
I'm surprised the compiler didn't complain about something like 'local definition hides instance var' or something similar
-Mark
hi Mark, yes it is complaining but I dont know how to "repair" it.. just delete one of them?
UIImage *new2 = [HelloWorldLayer scaleImage:newImage22 toSize:CGSizeMake(320,480)];
local declar. hides instance var.
Hi,
This is my code and working properly. May it help you;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[[SimpleAudioEngine sharedEngine] playEffect:@"Button_Click.mp3"];
if (puzzleSprite)
{
[[puzzleSprite parent] removeChild:puzzleSprite cleanup:YES];
puzzleSprite = nil;
}
if (puzzleImage)
{
puzzleImage = nil;
}
[[CCDirector sharedDirector] purgeCachedData]; // use this line to clear unused texture cache memory
// Dismiss the image selection, hide the picker and
//show the image view with the picked image
puzzleImage = (UIImage *)[info objectForKey:@"UIImagePickerControllerOriginalImage"];
CGSize size = [puzzleImage size];
if (size.width < size.height)
{
puzzleImage = [CCImageUtilities image:puzzleImage rotate:UIImageOrientationLeft];
}
puzzleImage = [CCImageUtilities image:puzzleImage fillSize:CGSizeMake(CANVAS_WIDTH, CANVAS_HEIGHT)];
[picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
[picker release];
picker = nil;
[_popover dismissPopoverAnimated:YES];
[_popover release];
[puzzleImage retain];
puzzleSprite = [CCSprite spriteWithCGImage:[puzzleImage CGImage] key:[NSString stringWithFormat:@"%.0f",CFAbsoluteTimeGetCurrent()]];
// puzzleSprite = [CCSprite spriteWithCGImage:[puzzleImage CGImage] key:nil]; // I am using this
[self addChild:puzzleSprite];
[puzzleSprite setPosition:ccp(511, 768 - 436)];
}ok i will try it anyway, it is interesting that klucCislo++; do nothing.. integer is still ONE.. no adding..
KNIGHTKROWS - IT IS WORKING NOW!!! the magic was in
[[CCDirector sharedDirector] purgeCachedData];
:)) THANK YOU AGAIN!
you welcome buddy :)
I'm having some problems, what is the code for the button you are using to launch the image picker?
thanks
Thanks a million rcbowser. I was having the same problem as apple.dev. Your post heled me from a mess. I was unable to figure out where was the problem and posted a new Thread in cocos2d. Here is the Link:
http://www.cocos2d-iphone.org/forum/topic/30638
The line
[picker presentModalViewController:picker animated:YES];
throws the exception
2012-03-29 21:26:09.844 [918:1be03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modal view controller on itself. Presenting controller is <UIImagePickerController: 0x94c1410>.'
How is this problem solved today (latest Xcode and iOS SDKs) for showing an UIImagePickerController on iPhone? icker must be replaced by some other object?
You must log in to post.