UIImageOrientation/UIImagePickerController - uiimagepickercontroller

I am using the Camera to take pictures in an IOS app.
It works, the only issue I have is when I try to figure out how the user was holding the device when taking the picture.
It would be much better if I could display the images in a proper way, not upside down or rotated 90 degrees.
Looking for a solution leads me to the fact that I should use the imageOrientation of UIImage but in reality:
theImage.imageOrientation is always equal to UIImageOrientationUp
What am I missing?
I did various research and experiment but nothing changes.
I am not showing any more code at this point, for the simple reason, I do not know which part to show to help find the problem.

Since I was able to find a solution on my own. I put it here, in case it may be useful to someone else.
Looking at the value of the "imageOrientation" field on the saved image (like I was doing), indeed for some reason always shows up as UIImageOrientationUp.
On the other hand looking at it inside the imagePickerController:didFinishPickingMediaWithInfo: is much more meaningful.
After some more research and trials, I ended up with a method looking like that:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
……
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
……
if ((image.imageOrientation==UIImageOrientationLeft)||
(image.imageOrientation==UIImageOrientationRight)||
(image.imageOrientation==UIImageOrientationDown)) {
UIGraphicsBeginImageContext(image.size);
[image drawAtPoint:CGPointMake(0.0, 0.0)];
image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
NSData *mediaData = UIImagePNGRepresentation(image);
……
}
And then my picture shows properly oriented, when I want to use it later in my app.

Related

Stackmob fetchExtended not working

I have started to use Stackmob as a backend for a simple app I am building.
In stackmob I have set a relationship between two schema's and want to use '.fetchExpanded' to grab all of the data from stackmob, see this fiddle (will need to view the console to see the output):
http://jsfiddle.net/mcneela86/65Rax/
.fetchExtended(1);
The same code works using the '.fetch' instead of '.fetchExpanded'.
Has anyone come across this before?
Would really appreciate any help.
Ok, I found a work around for this.
Instead of using '.fetchExtended(1);' I will just use '.fetch();' and when I am defining the model I will change the following:
var Bike = StackMob.Model.extend({
schemaName: "bikes"
});
to:
var Bike = StackMob.Model.extend({
schemaName: "bikes?_expand=1"
});
This seems to remove the need for '.fetchExtended(1);'
Hope this helps someone else.

UIGestureRecognizer on multiple view

There is several examples on here about how to get multiple views recognized by a single UIGestureRecognizer. I have this code, and i've tried varies ways to get it work but unfortunately doesn't seem to work. I would appreciate it if one can shed some light on this.
the only way that i was able to get it to work if I create several (IBAction) functions but i have up to 100 views that need to be moved around so that would require to have 100 different functions. I read an example here where tag can be used to do just that but i tried it and unfortunately it does not work. I'm using XCode 4.6.1 if that helps. Here's the code below.
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
UIView *player=recognizer.view;
int tag=player.tag;
[player addGestureRecognizer:recognizer];
if (tag!=0) {
CGPoint translation =[recognizer translationInView:self.view];
player.center=CGPointMake(player.center.x+translation.x, player.center.y+translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:player.superview];
}
}
It seems to me that you are adding the same gesture recognizer to the view that already has it. You could use a loop using the tag to add the UIPanGestureRecognizer to all your views and then in the method handlePan:(UIPanGestureRecognizer *)recognizer check which view is currently being panned and continue from there.

Game Maker Code doing the opposite?

if keyboard_check('D')
{
x = x + 4
sprite_index = spr_playerRight
}
As soon as I start the game, the player sprite will start moving to the right. But, as you can see, that shouldn't be happening... right?
When I actually do press D, it does the (Else) portion of the little chunk.
Any idea why this is happening? I'm a bit new to this.
Edit: I was messing around a little and I swapped the code (the IF from the else) and I would not move at the start, but pressing any key would cause me to move.
Another Edit: The fact that the Else would apply any time the D key is not applied made me realize that (if this did work properly) the else on this would intrude on attempts to move other directions (Pressing any button will stop the movement)
Another Edit: I changed the keyboard_check to
keyboard_check(vk_right)
And it works perfectly fine. I believe this is simple a problem on how I declared the key... How do I declare keys properly?
According to the documentation it should be:
if keyboard_check(ord('D'))

Google maps API v3 - externally controlling radius on distanceWidget

this seems pretty specific to ask - but there was no other alternative to the expertbase of stackoverflow!
I'm stuck in a problem where I need to control the radius of the circle by an external means such as a dropdown or a textbox.
I had a hard time doing the circle and had to copy stuff from the Twitter search example on:
http://code.google.com/apis/maps/articles/mvcfun/twittersearch.html
Ideally, I would like to know how to bind an external even to the radiusWidget, the problem is - the sizer inside the radiusWidget seems a private entity.
It would be awesome if someone could hit me in the face with a bang!
Thx
distanceWidget.set('distance', XXX) should work. If you read the MVC article you can see how the binding is bi-directional.
You can look at the source of the Twitter example by downloading it to your computer, as you likely already did. When you have the source you can adapt it to your purposes as you like. The software usage rights (terms of usage, license, etc), if they are any, have to be respected of course.
In the case of the RadiusWidget you would just do:
function RadiusWidget(opt_distance) {
// ...
this.sizer = this.addSizer_(); // sizer is now accessible in RadiusWidget
}
RadiusWidget.prototype.addSizer_ = function() {
var sizer = ...
// ...
return sizer;
}

Flex: Dynamically create a preview image for a video

I'm using the VideoDisplay to play flv's, mov's, and mp4's and everything is working great. They are all being loaded via progressive download and are not being streamed. What I'd like to do is to grab a single specified frame (like whatever is being shown at the 10 second mark), convert it to a bitmap and use that bitmap as the preview image for the video. I'd like to do this at runtime so I don't have to create a preview image for every video that would be shown.
Any idea's on how to do this? I'd rather not fake it by playing it - seeking for that specific frame and then pausing it but I may have no other choice?
Ryan and James are correct -- the right way's probably to extract frames at upload/transcode-time. But if that's not an option, you could opt for using some sort of a default/placeholder image of your own (something generic or somehow suitable for all videos whose thumbs haven't yet been captured), and just use VideoDisplay's DisplayObject-ness to grab and then upload a frame to your server, e.g.:
<mx:Script>
<![CDATA[
var captured:Boolean;
private function creationCompleteHandler(event:Event):void
{
videoDisplay.source = "http://yourserver/yourvideo.flv";
}
private function videoDisplay_playheadUpdate(event:VideoEvent):void
{
if (!captured && videoDisplay.playheadTime >= 10)
capture();
}
private function capture():void
{
var bmpData:BitmapData = new BitmapData(videoDisplay.width, videoDisplay.height);
bmpData.draw(videoDisplay);
captured = true;
// Now just upload the byte array to your server for the next user
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
// ... etc.
}
]]>
</mx:Script>
<mx:VideoDisplay id="videoDisplay" playheadUpdate="videoDisplay_playheadUpdate(event)" />
Again, it's perhaps not the most elegant solution, but it certainly works. This way, the first user sees the generic image, but every user thereafter gets the generated thumbnail. (Which, of course, you'll have uploaded and properly associated by then.) Make sense?
I'm pretty sure this isn't possible. It may well be... but don't think so. I think the only way to load in video is to use the NetStream and NetConnection object, which as you know just kicks off the loading of the video.
If this is user generated video i think the best bet is to have some serever side script that generates the preview image. Have no idea how this is done but think this is how most clip sites work.
If all the videos are in your control it may be possible to write a script for one of the video editing programs to automate generating the image for a specific frame from a list of files. I think this is probably your best route as alternative that you could get up and running quickly.
Sorry for the vague answer... it may point you in the right direction if you need a quick solution.
I agree with James, the only way to really do this would be to do it with a server side script and pull certain frames out of the video. Even if you could do this with flex, you really would not want to put the burden to do this (which would be processor intensive I would think) on the client machine. Not to mention it will be much more efficient to create the image before hand than to have flex determine the thumbnail to show every time it is loaded.

Resources