private static void InitializeDb_SqlServer()
    {
        using (SqlConnection connection = GetNewOpenDbConnection_SqlServer())
        {
            using (SqlCommand command = connection.CreateCommand())
            {
                // *** Initialize the [Ex_A_306] TABLE ******
                command.CommandText = "INSERT INTO [Ex_A_306] ([ID], [PictureTrimmerValue], [SourceImage], [OutputImage]) VALUES (@Id, @PictureTrimmerValue, @SourceImage, @OutputImage)";

                command.Parameters.AddWithValue("@Id", 1);

                string sourceImageFilePath = HttpContext.Current.Server.MapPath("~/repository/source/trevi1.jpg");
                command.Parameters.AddWithValue("@SourceImage", File.ReadAllBytes(sourceImageFilePath));

                string pictureTrimmerValueString = "{\"imageSelection\":{\"transformation\":{\"resizeFactor\":102.4734,\"rotationAngle\":0,\"flipH\":true,\"flipV\":false},\"crop\":{\"rectangle\":{\"x\":34,\"y\":37,\"width\":320,\"height\":180},\"canvasColor\":{\"value\":{\"a\":255,\"r\":255,\"g\":255,\"b\":255},\"autoUseTransparentColor\":true}}},\"imageAdjustments\":{\"brightness\":-1.973684,\"contrast\":5.921052,\"hue\":-180,\"saturation\":-13.1579},\"imageBackColorApplyMode\":1}";
                command.Parameters.AddWithValue("@PictureTrimmerValue", pictureTrimmerValueString);

                PictureTrimmerValue value = PictureTrimmerValue.FromJSON(pictureTrimmerValueString);
                command.Parameters.AddWithValue("@OutputImage", value.SaveProcessedImageToByteArray(sourceImageFilePath, new JpegFormatEncoderParams()));

                command.ExecuteNonQuery();
                // *********
            }
        }
    }
    protected void EditImage3()
    {
        // Load the image and the value from the DB
        using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection())
        {
            using (OleDbCommand command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [SourceImage],[PictureTrimmerValue] FROM [Ex_A_305] WHERE [Id]=@Id";
                command.Parameters.AddWithValue("@Id", RecordID3);
                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    reader.Read();

                    byte[] imageBytes      = (byte[])reader["SourceImage"];
                    string contentImageUrl = GetImageUrl_Content(RecordID3, this.popupPictureTrimmer3.ImageBackColor.Value, this.popupPictureTrimmer3.ImageBackColorApplyMode);
                    this.popupPictureTrimmer3.LoadImageFromByteArray(imageBytes, contentImageUrl, new FixedCropConstraint(320, 180));

                    // NOTE:
                    // The content image URL can be setted also after image load.
                    // This is useful to generate dynamic content images.
                    // Example:
                    // this.popupPictureTrimmer1.ContentImageUrl = "...";

                    this.popupPictureTrimmer3.Value = PictureTrimmerValue.FromJSON((string)reader["PictureTrimmerValue"]);
                }
            }
        }

        // Open the image edit popup
        this.popupPictureTrimmer3.OpenPopup(800, 510);
    }
    protected void EditImage1()
    {
        // Load the image in the control (the image file is stored in the file system)
        this.popupPictureTrimmer1.LoadImageFromFileSystem(string.Format("~/repository/store/ex_A_305/source/{0}.jpg", RecordID1), new FixedCropConstraint(320, 180));

        // Load the value (stored in the DB)
        using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection())
        {
            using (OleDbCommand command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [PictureTrimmerValue] FROM [Ex_A_305] WHERE [Id]=@Id";
                command.Parameters.AddWithValue("@Id", RecordID1);
                this.popupPictureTrimmer1.Value = PictureTrimmerValue.FromJSON((string)command.ExecuteScalar());
            }
        }

        // Open the image edit popup
        this.popupPictureTrimmer1.OpenPopup(800, 510);
    }
    protected void EditImage1()
    {
        // Load the image and the value from the DB
        using (SqlConnection connection = ExamplesHelper.GetNewOpenDbConnection_SqlServer())
        {
            using (SqlCommand command = connection.CreateCommand())
            {
                command.CommandText = "SELECT [SourceImage],[PictureTrimmerValue] FROM [Ex_A_306] WHERE [Id]=@Id";
                command.Parameters.AddWithValue("@Id", RecordID1);
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    reader.Read();

                    this.popupPictureTrimmer1.LoadImageFromByteArray((byte[])reader["SourceImage"], new FixedCropConstraint(320, 180));
                    this.popupPictureTrimmer1.Value = PictureTrimmerValue.FromJSON((string)reader["PictureTrimmerValue"]);
                }
            }
        }

        // Open the image edit popup
        this.popupPictureTrimmer1.OpenPopup(800, 510);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.ScriptManager1.IsInAsyncPostBack)
        {
            // After every Ajax postback re-initialize the JQuery UI elements
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true);
        }

        if (!this.IsPostBack)
        {
            // Get the record id passed as query parameter
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                this.RecordId = int.Parse(Request.QueryString["id"]);
            }

            // Setup the size of the preview image displayed in the Picture1 control (fixed size: 200x200 pixel)
            this.Picture1.PreviewFilter = new FixedResizeConstraint(200, 200);

            this.Picture1.Text_ConfigurationLabel = "<strong>Image orientation:&nbsp;</strong>";
            this.Picture1.Configurations          = new string[] { "Landscape", "Portrait" };

            #region Load the Record
            if (this.RecordId != 0)
            {
                // UPDATE
                this.labelRecordId.Text = this.RecordId.ToString();

                // Load the database data
                using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection())
                {
                    using (OleDbCommand command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.Text;
                        command.CommandText = "SELECT [Title], [Picture1_Configuration], [Picture1_PictureTrimmerValue], [Picture1_FileName_upload], [Picture1_FileName_main], [Picture1_FileName_thumbnail] FROM [Ex_A_506] WHERE [Id]=@Id";
                        command.Parameters.AddWithValue("@Id", this.RecordId);

                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                // Record found

                                // Get the title
                                this.txtTitle.Text = Convert.ToString(reader["Title"]);

                                // Get the configuration index (0=landscape, 1=portrait)
                                // and apply the right crop constrait depending on the configuration
                                this.Picture1.SelectedConfigurationIndex = Convert.ToInt32(reader["Picture1_Configuration"]);
                                this.Picture1.CropConstraint             = this.GetCropConstraint(this.Picture1.SelectedConfigurationIndex.Value);

                                // Get the PictureTrimmer previous state
                                PictureTrimmerValue picture1Value = PictureTrimmerValue.FromJSON(Convert.ToString(reader["Picture1_PictureTrimmerValue"]));

                                // Get the picture1 file names
                                this.Picture1FileName_upload    = Convert.ToString(reader["Picture1_FileName_upload"]);
                                this.Picture1FileName_main      = Convert.ToString(reader["Picture1_FileName_main"]);
                                this.Picture1FileName_thumbnail = Convert.ToString(reader["Picture1_FileName_thumbnail"]);

                                if (!string.IsNullOrEmpty(this.Picture1FileName_upload))
                                {
                                    // Load the image into the SimpleImageUpload ASCX control
                                    string picture1FilePath_upload = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_506/picture1/upload/"), this.Picture1FileName_upload);
                                    this.Picture1.LoadImageFromFileSystem(picture1FilePath_upload, picture1Value);
                                }
                            }
                            else
                            {
                                // Record not found, return to list
                                this.ReturnToList();
                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                // NEW RECORD
                this.labelRecordId.Text = "New record";
            }
            #endregion
        }

        // Reset some settings after every postback...
        this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID;
    }
Example #6
0
    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
    }
    /// <summary>
    /// Loads an image from an array of bytes and applies a specific PictureTrimmerValue.</summary>
    /// <param name="sourceImage">The source image to load.</param>
    /// <param name="value">The PictureTrimmerValue to apply.</param>
    public void LoadImage(System.Drawing.Image sourceImage, PictureTrimmerValue value)
    {
        // Save the image - Use PNG as image format to preserve transparency
        ImageArchiver.SaveImageToFileSystem(sourceImage, this.TemporarySourceImageFilePath, new PngFormatEncoderParams());

        // Load the image into the control
        this.LoadImageFromFileSystem_Internal(this.TemporarySourceImageFilePath, sourceImage, sourceImage.Size, sourceImage.RawFormat.Guid, CodeCarvings.Piczard.Helpers.ImageHelper.GetImageResolution(sourceImage), false, value);
    }
    /// <summary>
    /// Loads an image from an array of bytes and applies a specific PictureTrimmerValue.</summary>
    /// <param name="sourceImage">The source image to load.</param>
    /// <param name="value">The PictureTrimmerValue to apply.</param>
    public void LoadImage(LoadedImage sourceImage, PictureTrimmerValue value)
    {
        // Save the image - Use PNG as image format to preserve transparency
        ImageArchiver.SaveImageToFileSystem(sourceImage.Image, this.TemporarySourceImageFilePath, new PngFormatEncoderParams());

        // Load the image into the control
        this.LoadImageFromFileSystem_Internal(this.TemporarySourceImageFilePath, sourceImage.Image, sourceImage.Size, sourceImage.FormatId, sourceImage.Resolution, false, value);
    }
    /// <summary>
    /// Loads an image from an array of bytes and applies a specific PictureTrimmerValue.</summary>
    /// <param name="sourceImageBytes">The array of bytes to load.</param>
    /// <param name="value">The PictureTrimmerValue to apply.</param>
    public void LoadImageFromByteArray(byte[] sourceImageBytes, PictureTrimmerValue value)
    {
        //Save the byte array
        using (Stream writer = File.Create(this.TemporarySourceImageFilePath))
        {
            writer.Write(sourceImageBytes, 0, sourceImageBytes.Length);
            writer.Close();
        }

        // Load the image from the temporary file
        this.LoadImageFromFileSystem_Internal(this.TemporarySourceImageFilePath, value);
    }
    /// <summary>
    /// Loads an image from a Stream and applies a specific PictureTrimmerValue.</summary>
    /// <param name="sourceImageStream">The Stream containing the image to load.</param>
    /// <param name="value">The PictureTrimmerValue to apply.</param>
    public void LoadImageFromStream(Stream sourceImageStream, PictureTrimmerValue value)
    {
        // Save the stream
        using (Stream writer = File.Create(this.TemporarySourceImageFilePath))
        {
            if (sourceImageStream.Position != 0)
            {
                sourceImageStream.Seek(0, SeekOrigin.Begin);
            }

            byte[] buffer = new byte[4096];
            int readBytes;
            while (true)
            {
                readBytes = sourceImageStream.Read(buffer, 0, buffer.Length);
                if (readBytes <= 0)
                {
                    break;
                }
                writer.Write(buffer, 0, readBytes);
            }

            writer.Close();
        }

        // Load the image from the temporary file
        this.LoadImageFromFileSystem_Internal(this.TemporarySourceImageFilePath, value);
    }
    /// <summary>
    /// Loads an image stored in the file system and applies a specific PictureTrimmerValue.</summary>
    /// <param name="sourceImageFilePath">The path of the image to load.</param>
    /// <param name="value">The PictureTrimmerValue to apply.</param>
    public void LoadImageFromFileSystem(string sourceImageFilePath, PictureTrimmerValue value)
    {
        // Translate path to absolute
        sourceImageFilePath = CodeCarvings.Piczard.Helpers.IOHelper.TranslatePathToAbsolute(sourceImageFilePath);

        // Copy the source image into the temporary folder
        // So there is no problem il the original source image is deleted (e.g. when a record is updated...)
        System.IO.File.Copy(sourceImageFilePath, this.TemporarySourceImageFilePath, true);

        // Load the image
        this.LoadImageFromFileSystem_Internal(this.TemporarySourceImageFilePath, value);

        // Use the original file name as source client file name
        this.SourceImageClientFileName = sourceImageFilePath;
    }
 protected void LoadImageFromFileSystem_Internal(string sourceImageFilePath, PictureTrimmerValue value)
 {
     using (LoadedImage image = ImageArchiver.LoadImage(sourceImageFilePath))
     {
         this.LoadImageFromFileSystem_Internal(sourceImageFilePath, image.Image, image.Size, image.FormatId, image.Resolution, true, value);
     }
 }
    protected void LoadImageFromFileSystem_Internal(string sourceImageFilePath, System.Drawing.Image sourceImage, Size sourceImageSize, Guid sourceImageFormatId, float sourceImageResolution, bool disposeSourceImage, PictureTrimmerValue value)
    {
        // Calculate the client file name
        this.SourceImageClientFileName = "noname" + ImageArchiver.GetFormatEncoderParams(sourceImageFormatId).FileExtension;

        if (CodeCarvings.Piczard.Configuration.WebSettings.PictureTrimmer.UseTemporaryFiles)
        {
            // The picture trimmer can use temporary files -> Load the image now
            // This generates a new temporary files, however saves CPU and RAM
            this.popupPictureTrimmer1.LoadImage(sourceImage, this._OutputResolution, this._CropConstraint);
        }
        if (disposeSourceImage)
        {
            // The source image is no longer necessary
            sourceImage.Dispose();
            sourceImage = null;
        }

        if (!CodeCarvings.Piczard.Configuration.WebSettings.PictureTrimmer.UseTemporaryFiles)
        {
            // The picture trimmer cannot use temporary files -> Load the image now
            this.popupPictureTrimmer1.SetLoadImageData_ImageSize(sourceImageSize);
            this.popupPictureTrimmer1.SetLoadImageData_ImageResolution(sourceImageResolution);
            this.popupPictureTrimmer1.SetLoadImageData_ImageFormatId(sourceImageFormatId);

            this.popupPictureTrimmer1.LoadImageFromFileSystem(sourceImageFilePath, this._OutputResolution, this._CropConstraint);
        }

        if (value != null)
        {
            // Optional: Set the picture trimmer value
            this.popupPictureTrimmer1.Value = value;
        }

        // The new image has been loaded
        this._ImageUploaded = false;
        this._ImageEdited = false;

        // Update the preview
        this._UpdatePreview = true;
    }
Example #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.ScriptManager1.IsInAsyncPostBack)
        {
            // After every Ajax postback re-initialize the JQuery UI elements
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true);
        }

        if (!this.IsPostBack)
        {
            // Get the record id passed as query parameter
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                this.RecordId = int.Parse(Request.QueryString["id"]);
            }

            // Setup the Picture1 CropConstraint and the Preview Resize constraint
            this.Picture1.CropConstraint = new FixedCropConstraint(300, 300);
            this.Picture1.CropConstraint.DefaultImageSelectionStrategy = CropConstraintImageSelectionStrategy.WholeImage;
            this.Picture1.PreviewFilter = null; //Use the selected image

            #region Load the Record
            if (this.RecordId != 0)
            {
                // UPDATE
                this.labelRecordId.Text = this.RecordId.ToString();

                // Load the database data
                using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection())
                {
                    using (OleDbCommand command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.Text;
                        command.CommandText = "SELECT [Title], [Picture1_PictureTrimmerValue], [Picture1_FileName_upload], [Picture1_FileName_main], [Picture1_FileName_thumbnail] FROM [Ex_A_503] WHERE [Id]=@Id";
                        command.Parameters.AddWithValue("@Id", this.RecordId);

                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                // Record found

                                // Get the title
                                this.txtTitle.Text = Convert.ToString(reader["Title"]);

                                // Get the PictureTrimmer previous state
                                PictureTrimmerValue picture1Value = PictureTrimmerValue.FromJSON(Convert.ToString(reader["Picture1_PictureTrimmerValue"]));

                                // Get the picture1 file names
                                this.Picture1FileName_upload    = Convert.ToString(reader["Picture1_FileName_upload"]);
                                this.Picture1FileName_main      = Convert.ToString(reader["Picture1_FileName_main"]);
                                this.Picture1FileName_thumbnail = Convert.ToString(reader["Picture1_FileName_thumbnail"]);

                                if (!string.IsNullOrEmpty(this.Picture1FileName_upload))
                                {
                                    // Load the image into the SimpleImageUpload ASCX control
                                    string picture1FilePath_upload = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_503/picture1/upload/"), this.Picture1FileName_upload);
                                    this.Picture1.LoadImageFromFileSystem(picture1FilePath_upload, picture1Value);
                                }
                            }
                            else
                            {
                                // Record not found, return to list
                                this.ReturnToList();
                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                // NEW RECORD
                this.labelRecordId.Text = "New record";
            }
            #endregion
        }

        // Reset some settings after every postback...
        this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.ScriptManager1.IsInAsyncPostBack)
        {
            // After every Ajax postback re-initialize the JQuery UI elements
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true);
        }

        if (!this.IsPostBack)
        {
            // Get the record id passed as query parameter
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                this.RecordId = int.Parse(Request.QueryString["id"]);
            }

            // Setup the Picture1 Crop constraint and the preview filter
            this.Picture1.CropConstraint = new FixedCropConstraint(300, 300);
            this.Picture1.PreviewFilter  = new FixedResizeConstraint(100, 100);

            #region Load the Record
            if (this.RecordId != 0)
            {
                // UPDATE
                this.labelRecordId.Text = this.RecordId.ToString();

                // Load the database data
                using (SqlConnection connection = ExamplesHelper.GetNewOpenDbConnection_SqlServer())
                {
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.Text;
                        command.CommandText = "SELECT [Title], [Picture1_pictureTrimmerValue], [Picture1_file_upload] FROM [Ex_A_505] WHERE [Id]=@Id";
                        command.Parameters.AddWithValue("@Id", this.RecordId);

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                // Record found

                                // Get the title
                                this.txtTitle.Text = Convert.ToString(reader["Title"]);

                                // Get the picture1 PictureTrimmerValue
                                string picture1_pictureTrimmerValue = Convert.ToString(reader["Picture1_pictureTrimmerValue"]);
                                if (!string.IsNullOrEmpty(picture1_pictureTrimmerValue))
                                {
                                    PictureTrimmerValue pictureTrimmerValue = PictureTrimmerValue.FromJSON(picture1_pictureTrimmerValue);

                                    // Get the original file bytes
                                    byte[] picture1_file_upload = (byte[])(reader["Picture1_file_upload"]);
                                    if (picture1_file_upload.Length > 0)
                                    {
                                        // Load the image into the SimpleImageUpload ASCX control
                                        this.Picture1.LoadImageFromByteArray(picture1_file_upload, pictureTrimmerValue);
                                    }
                                }
                            }
                            else
                            {
                                // Record not found, return to list
                                this.ReturnToList();
                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                // NEW RECORD
                this.labelRecordId.Text = "New record";
            }
            #endregion
        }

        // Reset some settings after every postback...
        this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID;
    }