Sub RotateImageByDegrees(original As Bitmap, degree As Float) As Bitmap
original= nome.RunMethod("imageRotatedByDegrees::", Array(original,degree))
Return original
End Sub
Sub RotateImageByRadians(original As Bitmap, radians As Float) As Bitmap
original= nome.RunMethod("imageRotatedByRadians::", Array(original,radians))
Return original
End Sub
#If OBJC
CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
CGFloat RadiansToDegrees(CGFloat radians) {return radians * 180/M_PI;};
- (UIImage *)imageRotatedByRadians:(UIImage *)bmp:(CGFloat)radians
{
return [self imageRotatedByDegrees:bmp:RadiansToDegrees(radians)];
}
- (UIImage *)imageRotatedByDegrees:(UIImage *)bmp:(CGFloat)degrees
{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,bmp.size.width, bmp.size.height)];
CGAffineTransform t = CGAffineTransformMakeRotation(DegreesToRadians(degrees));
rotatedViewBox.transform = t;
CGSize rotatedSize = rotatedViewBox.frame.size;
// Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
// Move the origin to the middle of the image so we will rotate and scale around the center.
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
// Rotate the image context
CGContextRotateCTM(bitmap, DegreesToRadians(degrees));
// Now, draw the rotated/scaled image into the context
CGContextScaleCTM(bitmap, 1.0, -1.0);
CGContextDrawImage(bitmap, CGRectMake(-bmp.size.width / 2, -bmp.size.height / 2, bmp.size.width, bmp.size.height), bmp.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
#End If