Example #1
0
        private Bitmap RenderPreviewImage()
        {
            //the base preview is what the watermark will be added to
            var basePreview = Resources.flower_preview;

            ImageRenderer.WmContext = GlobalWmContext;

            //rendering procedure will change depending on the watermarking type
            switch (GlobalWmContext.BetaWatermarkType)
            {
            case WatermarkType.Text when txtImageText.Text != string.Empty:
            {
                //render image
                var result = ImageRenderer.RenderTextWatermark(txtImageText.Text, basePreview);

                //return the resulting watermarked preview
                return(result);
            }

            case WatermarkType.Image:
            {
                if (ImageSelected)
                {
                    //the watermark is loaded into memory
                    var watermark = (Bitmap)Image.FromFile(txtImageURI.Text);

                    //render image
                    var result = ImageRenderer.RenderImageWatermark(watermark, basePreview);

                    //return the resulting watermarked preview
                    return(result);
                }

                break;
            }
            }

            //default
            return(basePreview);
        }
Example #2
0
        public static void ConvertImageMagickNet(string fileName, string outputFolder, AppOptions options)
        {
            try
            {
                using (FileStream fi = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, _bufferSize, FileOptions.None))
                {
                    string baseName = Path.GetFileNameWithoutExtension(fileName);
                    string jpgName  = Path.Combine(outputFolder, baseName + ".jpg");
                    string wmkName  = Path.Combine(outputFolder, baseName + "_watermarked.jpg");
                    string extName  = GetSimpleExtension(fileName).ToLower();

                    Bitmap bitmap = Resources.flower_preview;

                    if (extName == "cr2")
                    {
                        MagickImage img = new MagickImage(fi);
                        bitmap = img.ToBitmap();
                    }
                    else if (options.ProcessJpeg)
                    {
                        //MessageBox.Show("Yee");
                        if (extName == "jpg")
                        {
                            //MessageBox.Show(extName);
                            bitmap = (Bitmap)Image.FromFile(fileName);
                        }
                    }

                    EncoderParameters ep = new EncoderParameters(1);
                    ep.Param[0] = new EncoderParameter(Encoder.Quality, options.Quality);

                    ImageRenderer.WmContext = WmContext;

                    if (WmContext.BetaWatermarkType == WatermarkType.Image)
                    {
                        Bitmap watermark = (Bitmap)Image.FromFile(WmContext.BetaWatermarkInfo.WatermarkPath);
                        Bitmap image     = ImageRenderer.RenderImageWatermark(watermark, bitmap);
                        image.Save(wmkName, JpgImageCodec, ep);

                        if (options.Duplicates)
                        {
                            bitmap.Save(jpgName, JpgImageCodec, ep);
                        }
                    }
                    else if (WmContext.BetaWatermarkType == WatermarkType.Text)
                    {
                        string watermark = WmContext.BetaWatermarkInfo.WatermarkText;
                        Bitmap image     = ImageRenderer.RenderTextWatermark(watermark, bitmap);
                        image.Save(wmkName, JpgImageCodec, ep);

                        if (options.Duplicates)
                        {
                            bitmap.Save(jpgName, JpgImageCodec, ep);
                        }
                    }
                    else if (WmContext.BetaWatermarkType == WatermarkType.None)
                    {
                        bitmap.Save(jpgName, JpgImageCodec, ep);
                    }

                    GC.Collect();
                }
            }
            catch (ThreadAbortException ex)
            {
                //do absolutely nil
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error whilst converting", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (FrmMain.BwConverter.IsBusy)
                {
                    FrmMain.BwConverter.Abort();
                }
            }
        }