OdessaGUIProject.Workers.SaveWorker.SaveWatermarkToDisk C# (CSharp) Method

SaveWatermarkToDisk() private static method

private static SaveWatermarkToDisk ( int videoWidth, int videoHeight, string watermarkPath ) : void
videoWidth int
videoHeight int
watermarkPath string
return void
        private static void SaveWatermarkToDisk(int videoWidth, int videoHeight, string watermarkPath)
        {
            Bitmap bm;

            /* We now generate bitmap on the fly
            if (videoWidth == 848 && videoHeight == 480)
                bm = Resources.watermark_848x480;
            else if (videoWidth == 1280 && videoHeight == 720)
                bm = Resources.watermark_1280x720;
            else if (videoWidth == 1280 && videoHeight == 960)
                bm = Resources.watermark_1280x960;
            else if (videoWidth == 1920 && videoHeight == 1080)
                bm = Resources.watermark_1920x1080;
            else if (videoWidth == 1920 && videoHeight == 1088)
                bm = Resources.watermark_1920x1088;
            else
                bm = Resources.watermark_848x480;
            */

            // take off 16 pixels because sometimes we think the dimensions are longer than it really is. this is an ffmpeg bug.
            videoWidth -= 16;
            videoHeight -= 16;

            int shortestSide;
            if (videoWidth > videoHeight)
                shortestSide = videoHeight;
            else
                shortestSide = videoWidth;

            var logoDimension = (int)(shortestSide * 0.05);

            Image logo;
            if (logoDimension <= 16)
                logo = Resources.watermark_16x16;
            else if (logoDimension <= 24)
                logo = Resources.watermark_24x24;
            else if (logoDimension <= 36)
                logo = Resources.watermark_36x36;
            else if (logoDimension <= 48)
                logo = Resources.watermark_48x48;
            else if (logoDimension <= 54)
                logo = Resources.watermark_54x54;
            else
                logo = Resources.watermark_64x64;

            var logoPoint = new Point(videoWidth - logo.Width * 2, videoHeight - logo.Height * 2);

            var image = new Bitmap(videoWidth, videoHeight, PixelFormat.Format32bppArgb);
            using (var g = Graphics.FromImage(image))
            {
                g.DrawImageUnscaled(logo, logoPoint);
            }

            bm = image;

            #region The MD5 hash is being computed differently on Win7 and WinXP. Until I figure this out, I'm disabling it

            /*

            // verify valid CRCs from Bitmap object
            var converter = new ImageConverter();

            string contents = converter.ConvertToInvariantString(bm);
            Logger.Info("Contents: " + contents);

            var rawImageData = converter.ConvertTo(bm, typeof(byte[])) as byte[];
            if (rawImageData == null)
                throw new Exception("Watermarks have been tampered with!");

            //byte[] rawImageData = File.ReadAllBytes(watermarkPath);

            var md5 = new MD5CryptoServiceProvider();
            byte[] data = md5.ComputeHash(rawImageData);
            var thisCRC = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                thisCRC.Append(data[i].ToString("X2"));
            }

            #if DEBUG
            Logger.Info("Hash: " + thisCRC);
            #endif

            const string crc848X480 = "FD84A7D38F05C1E189FDC7FDDF34DF8";
            const string crc1280X720 = "132670E229B21145AAB77047CCCCFE";
            const string crc1280X960 = "321777DBE5FAC821D45A2FB92EB63869";
            const string crc1920X1080 = "699AC9FB4751E9A83D6BAB21DB3270";
            const string crc1920X1088 = "699AC9FB4751E9A83D6BAB21DB3270";

            bool isCRCValid;
            if (videoWidth == 848 && videoHeight == 480)
                isCRCValid = (thisCRC.ToString() == crc848X480);
            else if (videoWidth == 1280 && videoHeight == 720)
                isCRCValid = (thisCRC.ToString() == crc1280X720);
            else if (videoWidth == 1280 && videoHeight == 960)
                isCRCValid = (thisCRC.ToString() == crc1280X960);
            else if (videoWidth == 1920 && videoHeight == 1080)
                isCRCValid = (thisCRC.ToString() == crc1920X1080);
            else if (videoWidth == 1920 && videoHeight == 1088)
                isCRCValid = (thisCRC.ToString() == crc1920X1088);
            else
                isCRCValid = (thisCRC.ToString() == crc848X480);

            if (isCRCValid == false)
            {
                throw new Exception("Watermarks have been tampered with!");
            }

             */

            #endregion The MD5 hash is being computed differently on Win7 and WinXP. Until I figure this out, I'm disabling it

            // watermarks passed CRC check
            try
            {
            #if DEBUG
                Logger.Info("Saving to " + watermarkPath);
            #endif
                bm.Save(watermarkPath, ImageFormat.Png);
            }
            catch (System.Runtime.InteropServices.ExternalException ex)
            {
                Logger.Error("Exception while saving: " + ex);
            }
        }