iPhone Image Captured from Camera Rotate -90 Degree Automatically

Why rotate Image in OpenCV without rotation code?

Are you using UIImageJPEGRepresentation to get these images out? If so, then you might be interested in this:

http://blog.logichigh.com/2008/06/05/uiimage-fix/

--> "UIImageJPEGRepresentation(), the easiest (only?) way to convert a UIImage to a JPEG uses the underlying CGImage, and ignores your UIImage imageOrientation, so regardless of camera position when the picture was taken the exported JPEG will always be oriented in landscape or right mode, ending up with pictures that need rotation."

This hints that even if you are not using this function, there is an implicit imageOrientation to consider when using UIImage.

iS rotate view CGAffineTransformMakeRotation

UIView *myView = [[UIView alloc] init];
[myView setTransform:CGAffineTransformMakeRotation(M_PI)];

10 degrees rotation image cut off

I solved it now, i have to change the width/height value of bounds and
the x/y in CGContextDrawImage

CGRect bounds = CGRectMake(0, 0, width+10, height+10);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(10,0,width,height), imgRef);

Rotate UIImageView Gradually using a timer

Try this :

Start the animation:

  CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(2*M_PI)];
rotation.duration = 1.0;// Speed
rotation.repeatCount = HUGE_VALF;// Repeat forever.
[imgViewCube.layer addAnimation:rotation forKey:@"Spin"];

Stop the animation:

  [imgViewCube.layer removeAnimationForKey:@"Spin"];

Rotation and cropping an image IOS

Use the following snippet for rotating image data.

The input data is inAngle (angle in radians) and inImage (UIImage instance).

What this does, it creates an image context, applies the transformation to it and draws the original image into that context. The resulting image data will now be stored in resultImage.

The first three lines handle the calculation of the bounding result image frame.

UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, inImage.size.width, inImage.size.height)];
rotatedViewBox.transform = CGAffineTransformMakeRotation(inAngle);
CGSize rotatedSize = rotatedViewBox.frame.size;

UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(bitmap, rotatedSize.width / 2.0f, rotatedSize.height / 2.0f);
CGContextRotateCTM(bitmap, inAngle);
CGContextScaleCTM(bitmap, 1.0f, -1.0f);
CGContextDrawImage(bitmap, CGRectMake(-inImage.size.width / 2.0f,
-inImage.size.height / 2.0f,
inImage.size.width,
inImage.size.height),
inImage.CGImage);
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Turn camera picture depending on the device orientation (Xamarin.iOS)

Try this :

var currentOrientation = UIApplication.SharedApplication.StatusBarOrientation;

if (currentOrientation == UIInterfaceOrientation.Portrait)
{
videoConnection.VideoOrientation = AVCaptureVideoOrientation.Portrait;
}
else if (currentOrientation == UIInterfaceOrientation.LandscapeRight)
{
videoConnection.VideoOrientation = AVCaptureVideoOrientation.LandscapeRight;
}
//xxx

Update:

If the app only supports an orientation or you lock the screen , there is another old way to detect device orientation. Core Motion

public void LockOrientation()
{
CMMotionManager CMManager = new CMMotionManager();
CMManager.DeviceMotionUpdateInterval = 0.2f;
CMManager.StartDeviceMotionUpdates(NSOperationQueue.MainQueue, (motion, error) => {
if (Math.Abs(motion.Gravity.X) > Math.Abs(motion.Gravity.Y))
{
Console.WriteLine("Lan");
if (motion.Gravity.X > 0)
{
UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeLeft), new NSString("orientation"));
Console.WriteLine("Left");
}
else
{
UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeRight), new NSString("orientation"));
Console.WriteLine("Right");
}
}
else
{
if (motion.Gravity.Y >= 0)
{
Console.WriteLine("Down");
}
else
{
Console.WriteLine("UP");
}
}

CMManager.StopDeviceMotionUpdates();
});
}

Refer to here



Related Topics



Leave a reply



Submit