private void MoveOrResize( AnnotationBoundingBox boundingBox, PointF translation, CanvasInfo canvasInfo, KeyboardOperation keyboardOperation, ScaleOperation scaleOperation) { if (keyboardOperation == KeyboardOperation.Move) { boundingBox.CenterX += translation.X / (float)canvasInfo.ScaledWidth; boundingBox.CenterY += translation.Y / (float)canvasInfo.ScaledWidth; boundingBox.CenterX = boundingBox.CenterX.Clamp(boundingBox.Width / 2, 1 - boundingBox.Width / 2); boundingBox.CenterY = boundingBox.CenterY.Clamp(boundingBox.Height / 2, 1 - boundingBox.Height / 2); } else { var inverseFac = (scaleOperation == ScaleOperation.Inverse ? -1 : 1); var newCenterX = boundingBox.CenterX + translation.X / (float)canvasInfo.ScaledWidth / 2; var newWidth = boundingBox.Width + translation.X / (float)canvasInfo.ScaledWidth * inverseFac; if (newCenterX - newWidth / 2 >= 0 && newCenterX + newWidth / 2 <= 1 && newWidth * canvasInfo.ScaledWidth > this._minSize.Width) { boundingBox.CenterX = newCenterX; boundingBox.Width = newWidth; } var newCenterY = boundingBox.CenterY + translation.Y / (float)canvasInfo.ScaledHeight / 2; var newHeight = boundingBox.Height + translation.Y / (float)canvasInfo.ScaledHeight * inverseFac; if (newCenterY - newHeight / 2 >= 0 && newCenterY + newHeight / 2 <= 1 && newHeight * canvasInfo.ScaledHeight > this._minSize.Height) { boundingBox.CenterY += translation.Y / (float)canvasInfo.ScaledHeight / 2; boundingBox.Height += translation.Y / (float)canvasInfo.ScaledHeight * inverseFac; } } }
private void loadSizesFromFile(string[] fileLines) { foreach (string l in fileLines) { //Ignore whitspace lines if (l.Trim().Length == 0) { continue; } //Ignore comment lines if (l.Trim().StartsWith("#")) { continue; } string[] parts = l.Trim().Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 1) { Logger.LogWarning("Ignoring " + l + " in " + SIZES_FILE); continue; } if (parts.Length == 0) { continue; } Size imageSize; ScaleOperation operation = ScaleOperation.Scale; string suffix = null; byte imageQuality = JPEG_QUALITY; string[] sizeOperationParts = parts[0].Split(':'); if (sizeOperationParts.Length > 1) { if (sizeOperationParts[1].ToLower() == "crop") { operation = ScaleOperation.Crop; } else { Logger.LogWarning("Unknown image processing option " + sizeOperationParts[0] + " in " + SIZES_FILE); } } string[] dimensions = sizeOperationParts[0].Split('x'); if (dimensions.Length == 2) { int width, height; if (!int.TryParse(dimensions[0], out width) || !int.TryParse(dimensions[1], out height)) { Logger.LogWarning("The value " + parts[0] + " in " + SIZES_FILE + " could not recognised as an image size. Expected <integer>x<integer>"); continue; } if (width < 1 || height < 1) { Logger.LogWarning("Both width and height must be positive integers - " + parts[0] + " in " + SIZES_FILE); continue; } imageSize = new Size() { Width = width, Height = height }; } else { Logger.LogWarning("The value " + parts[0] + " in " + SIZES_FILE + " could not recognised as an image size. Expected <integer>x<integer>"); continue; } if (parts.Length > 1) { suffix = parts[1]; } else { suffix = ""; } if (parts.Length > 2) { if (parts[2].EndsWith("%")) { byte quality; if (byte.TryParse(parts[2].Substring(0, parts[2].Length - 1), out quality)) { if (quality > 1 && quality <= 100) { imageQuality = quality; } } } else { Logger.LogMessage("Third argument on " + l + " in " + SIZES_FILE + " was not a percentage. Expected 'NN%'"); } } imageSizeInfo isi = new imageSizeInfo() { NameSuffix = suffix, Size = imageSize, QpalityPercent = imageQuality, Operation = operation }; imageSizes.Add(isi); } }