protected void LoadImageIntoPictureTrimmer(bool resetSelection) { // Pre-process the image ImageProcessingJob job = this.GetImagePreProcessingJob(); using (System.Drawing.Bitmap preProcessedImage = job.GetProcessedImage(SourceImageFileName)) { // Backup the previous userState PictureTrimmerUserState previousUserState = null; if (this.InlinePictureTrimmer1.ImageLoaded) { previousUserState = this.InlinePictureTrimmer1.UserState; } // Load the pre-processed image into the PictureTrimmer control this.InlinePictureTrimmer1.LoadImage(preProcessedImage, new FreeCropConstraint(null, 600, null, 600)); if (previousUserState != null) { if (resetSelection) { // Re-calculate the cropping rectangle previousUserState.Value.ImageSelection.Crop.Rectangle = null; // Re-center the image previousUserState.UIParams.PictureScrollH = null; previousUserState.UIParams.PictureScrollV = null; } // Restore the previous user state this.InlinePictureTrimmer1.UserState = previousUserState; } } }
protected void btnServerSideSetUserState_Click(object sender, EventArgs e) { // Set some random values Random rnd = new Random(); PictureTrimmerUserState userState = this.InlinePictureTrimmer1.UserState; // Set the resize factor userState.Value.ImageSelection.Transformation.ResizeFactor = rnd.Next(50, 150); // Horizontal flip userState.Value.ImageSelection.Transformation.FlipH = rnd.Next(0, 4) < 2; // Set the rectangle int x = rnd.Next(-100, 300); int y = rnd.Next(-100, 300); int w = rnd.Next(50, 400); int h = rnd.Next(50, 400); userState.Value.ImageSelection.Crop.Rectangle = new Rectangle(x, y, w, h); // Set the Saturation userState.Value.ImageAdjustments.Saturation = rnd.Next(-100, 100); // Auto-zoom and auto-center the view userState.UIParams.ZoomFactor = null; userState.UIParams.PictureScrollH = null; userState.UIParams.PictureScrollV = null; this.DisplayUserState(); }
protected void DisplayUserState() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); string crlf = "\r\n"; #region UserState PictureTrimmerUserState userState = this.InlinePictureTrimmer1.UserState; #region Value PictureTrimmerValue value = userState.Value; #region ImageSelection ImageSelection imageSelection = value.ImageSelection; #region ImageTransformation ImageTransformation imageTransformation = imageSelection.Transformation; sb.Length = 0; sb.Append("Resize factor:" + imageTransformation.ResizeFactor.ToString(CultureInfo.InvariantCulture) + "%" + crlf); sb.Append("Rotation angle:" + imageTransformation.RotationAngle.ToString(CultureInfo.InvariantCulture) + "°" + crlf); sb.Append("Flip horizontal:" + (imageTransformation.FlipH ? "yes" : "no") + crlf); sb.Append("Flip vertical:" + (imageTransformation.FlipV ? "yes" : "no") + crlf); this.txtUserState_Value_ImageSelection_Transformation.Text = sb.ToString(); #endregion #region ImageCrop ImageCrop imageCrop = imageSelection.Crop; sb.Length = 0; sb.Append("Rectangle:" + (imageCrop.Rectangle.HasValue ? imageCrop.Rectangle.Value.ToString() : "Auto") + crlf); // Note: in this example imageCrop.CanvasColor is not displayed. this.txtUserState_Value_ImageSelection_Crop.Text = sb.ToString(); #endregion #endregion #region ImageAdjustments ImageAdjustmentsFilter imageAdjustments = value.ImageAdjustments; sb.Length = 0; sb.Append("Brightness:" + imageAdjustments.Brightness.ToString(CultureInfo.InvariantCulture) + crlf); sb.Append("Contrast:" + imageAdjustments.Contrast.ToString(CultureInfo.InvariantCulture) + crlf); sb.Append("Hue:" + imageAdjustments.Hue.ToString(CultureInfo.InvariantCulture) + "°" + crlf); sb.Append("Saturation:" + imageAdjustments.Saturation.ToString(CultureInfo.InvariantCulture) + crlf); this.txtUserState_Value_ImageAdjustments.Text = sb.ToString(); #endregion // Note: In this example value.ImageBackColorApplyMode is not displayed. #endregion #region UIParams PictureTrimmerUIParams uiParams = userState.UIParams; sb.Length = 0; sb.Append("Zoom factor:" + (uiParams.ZoomFactor.HasValue ? uiParams.ZoomFactor.Value.ToString(CultureInfo.InvariantCulture) + "%" : "auto") + crlf); sb.Append("Picture scroll horizontal:" + (uiParams.PictureScrollH.HasValue ? uiParams.PictureScrollH.Value.ToString(CultureInfo.InvariantCulture) : "auto") + crlf); sb.Append("Picture scroll vertical:" + (uiParams.PictureScrollH.HasValue ? uiParams.PictureScrollV.Value.ToString(CultureInfo.InvariantCulture) : "auto") + crlf); sb.Append("Command panel scroll vertical:" + uiParams.CommandPanelScrollV.ToString(CultureInfo.InvariantCulture) + crlf); this.txtUserState_UIParams.Text = sb.ToString(); #endregion #endregion }