public void can_get_a_square_from_a_square_image() { var input = new SizeF(500, 500); var output = ImageCropLogic.GetLargestSquareFromRectangle(input); var target = new RectangleF(0, 0, 500, 500); Assert.AreEqual(target, output); }
public byte[] ResizeImage(byte[] imageBytes, int newWidth, int newHeight) { // byte[] -> NSData -> UIImage Byte[] NewByteArray = null; using (var data = NSData.FromArray(imageBytes)) { using (UIImage image = new UIImage(data)) { var cropRect = ImageCropLogic.GetLargestSquareFromRectangle(image.Size); var cropped = CropImage(image, cropRect); var resized = ResizeImage(cropped, newWidth, newHeight); using (NSData imageData = resized.AsPNG()) { NewByteArray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, NewByteArray, 0, Convert.ToInt32(imageData.Length)); } } } return(NewByteArray); }