/// <summary> /// Test encode functions /// </summary> private void ButtonSave_Click(object sender, System.EventArgs e) { byte[] rawWebP; try { if (this.pictureBox.Image == null) { MessageBox.Show("Please, load an image first"); } //get the picturebox image Bitmap bmp = (Bitmap)pictureBox.Image; //Test simple encode lossly mode in memory with quality 75 string lossyFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SimpleLossy.webp"); using (WebP webp = new WebP()) rawWebP = webp.EncodeLossy(bmp, 75); File.WriteAllBytes(lossyFileName, rawWebP); MessageBox.Show("Made " + lossyFileName, "Simple lossy"); //Test encode lossly mode in memory with quality 75 and speed 9 string advanceLossyFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AdvanceLossy.webp"); using (WebP webp = new WebP()) rawWebP = webp.EncodeLossy(bmp, 71, 9, true); File.WriteAllBytes(advanceLossyFileName, rawWebP); MessageBox.Show("Made " + advanceLossyFileName, "Advance lossy"); //Test simple encode lossless mode in memory string simpleLosslessFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SimpleLossless.webp"); using (WebP webp = new WebP()) rawWebP = webp.EncodeLossless(bmp); File.WriteAllBytes(simpleLosslessFileName, rawWebP); MessageBox.Show("Made " + simpleLosslessFileName, "Simple lossless"); //Test advance encode lossless mode in memory with speed 9 string losslessFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AdvanceLossless.webp"); using (WebP webp = new WebP()) rawWebP = webp.EncodeLossless(bmp, 9, true); File.WriteAllBytes(losslessFileName, rawWebP); MessageBox.Show("Made " + losslessFileName, "Advance lossless"); //Test encode near lossless mode in memory with quality 40 and speed 9 // quality 100: No-loss (bit-stream same as -lossless). // quality 80: Very very high PSNR (around 54dB) and gets an additional 5-10% size reduction over WebP-lossless image. // quality 60: Very high PSNR (around 48dB) and gets an additional 20%-25% size reduction over WebP-lossless image. // quality 40: High PSNR (around 42dB) and gets an additional 30-35% size reduction over WebP-lossless image. // quality 20 (and below): Moderate PSNR (around 36dB) and gets an additional 40-50% size reduction over WebP-lossless image. string nearLosslessFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NearLossless.webp"); using (WebP webp = new WebP()) rawWebP = webp.EncodeNearLossless(bmp, 40, 9, true); File.WriteAllBytes(nearLosslessFileName, rawWebP); MessageBox.Show("Made " + nearLosslessFileName, "Near lossless"); MessageBox.Show("End of Test"); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\nIn WebPExample.buttonSave_Click", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }