Пример #1
0
        /// <summary>
        /// Test for advanced decode function
        /// </summary>
        private void ButtonCropFlip_Click(object sender, EventArgs e)
        {
            try
            {
                using (OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog())
                {
                    openFileDialog.Filter   = "WebP files (*.webp)|*.webp";
                    openFileDialog.FileName = "";
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        string pathFileName = openFileDialog.FileName;

                        byte[]             rawWebP        = File.ReadAllBytes(pathFileName);
                        WebPDecoderOptions decoderOptions = new WebPDecoderOptions();
                        decoderOptions.use_cropping = 1;
                        decoderOptions.crop_top     = 100;  //Top beging of crop area
                        decoderOptions.crop_left    = 100;  //Left beging of crop area
                        decoderOptions.crop_height  = 400;  //Height of crop area
                        decoderOptions.crop_width   = 400;  //Width of crop area
                        decoderOptions.use_threads  = 1;    //Use multhreading
                        decoderOptions.flip         = 1;    //Flip the image
                        using (WebP webp = new WebP())
                            this.pictureBox.Image = webp.Decode(rawWebP, decoderOptions);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\nIn WebPExample.buttonCrop_Click", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
 public override FileTypeMan.OpenResult Open(string path)
 {
     try
     {
         byte[] rawWebP = File.ReadAllBytes(path);
         using (WebP webp = new WebP())
         {
             WebPDecoderOptions decoderOptions = new WebPDecoderOptions();
             decoderOptions.use_threads = 1;
             decoderOptions.alpha_dithering_strength = 100;
             return(new FileTypeMan.OpenResult
             {
                 Bmp = webp.Decode(rawWebP, decoderOptions)
             });
         }
     }
     catch
     {
         return(new FileTypeMan.OpenResult
         {
             ErrorMessage = TypeName + " - " + LangMan.Get("unable-open-file") + ": " + Path.GetFileName(path)
         });
     }
 }