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
How to Reference Instance Function When Calling Sequencetype.Foreach
Error When Trying to Call Setdata(From: ) in the Cloud Firestore iOS API. How to Fix It
Firebase .Indexon Dynamic Keys
How to Set Image in Tabbar Not Tint Color in iOS
How to Get Navigation Based Template Functionality in Swift Programming
Swift Uicolor Initializer - Compiler Error Only When Targeting Iphone5S
Swift - Using Replacerange() to Change Certain Occurrences in a String
Different Font Size for Different Devices in Xcode 6
Selector to Get Indexpath Uicollectionview Swift 3.0
How to Prevent iOS 13 Dark Mode from Breaking Emails
iOS 9 '-Webkit-Overflow-Scrolling:Touch' and 'Overflow: Scroll' Breaks Scrolling Capability
Swift - How to Save Memory Using Alamofireimage/Imageshack
What Is Lldb_Expr in Swift Playground