private void SetWallpaper(int imageId1, int imageId2, double percent)
        {
            string imageFilename1 = ThemeManager.currentTheme.imageFilename.Replace("*", imageId1.ToString());
            string imageFilename2 = ThemeManager.currentTheme.imageFilename.Replace("*", imageId2.ToString());

            string folder     = Path.Combine(Directory.GetCurrentDirectory(), "themes", ThemeManager.currentTheme.themeId);
            string imagePath1 = Path.Combine(folder, imageFilename1);
            string imagePath2 = Path.Combine(folder, imageFilename2);
            string outputPath = Path.Combine(folder, "current.jpg");

            Task.Run(() =>
            {
                var sw = new System.Diagnostics.Stopwatch();

                sw.Restart();
                using (var image1 = new ImageMagick.MagickImage(imagePath1))
                    using (var image2 = new ImageMagick.MagickImage(imagePath2))
                    {
                        image1.Quality = 98;
                        image1.Composite(image2, ImageMagick.CompositeOperator.Blend, Math.Round(percent * 100).ToString());
                        image1.Write(outputPath);
                    }
                sw.Stop();
                Console.WriteLine($"NEW: {sw.ElapsedMilliseconds}");

                GC.Collect();

                WallpaperApi.EnableTransitions();
                UwpDesktop.GetHelper().SetWallpaper("current.jpg");
            });

            lastImagePath = outputPath;
        }
        public ImageMagick.MagickImage GetWaterMap()
        {
            ImageMagick.MagickImage watermap = new ImageMagick.MagickImage(MpkWrapper.GetFileBytesFromMpk(this.m_datMpk, "water.pcx"));
            watermap.Resize(this.m_targetMapSize, this.m_targetMapSize);

            return(watermap);
        }
        private static string ExtractUrlFromQRImage(string qrCodeSetupImageUrl)
        {
            var headerLength = "data:image/png;base64,".Length;
            var rawImageData = qrCodeSetupImageUrl.Substring(headerLength, qrCodeSetupImageUrl.Length - headerLength);
            var imageData    = Convert.FromBase64String(rawImageData);

            //var reader = new BarcodeReaderGeneric();
            //reader.Options.PossibleFormats = new List<BarcodeFormat> {
            //    BarcodeFormat.QR_CODE
            //};

#if NETFRAMEWORK
            var reader = new BarcodeReader();
            reader.Options.PossibleFormats = new List <BarcodeFormat> {
                BarcodeFormat.QR_CODE
            };
            using (var ms = new MemoryStream(imageData))
            {
                var image = new System.Drawing.Bitmap(ms);
                return(reader.Decode(image).Text);
            }
#else
            var reader = new BarcodeReaderGeneric();
            reader.Options.PossibleFormats = new List <BarcodeFormat> {
                BarcodeFormat.QR_CODE
            };
            var image        = new ImageMagick.MagickImage(imageData);
            var wrappedImage = new ZXing.Magick.MagickImageLuminanceSource(image);
            return(reader.Decode(wrappedImage).Text);
#endif
        }
Example #4
0
        private void openFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(folderBrowserDialog1.SelectedPath))
            {
                string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);

                Task.Factory.StartNew(() =>
                {
                    foreach (var item in files)
                    {
                        try
                        {
                            ImageMagick.MagickImage img = new ImageMagick.MagickImage(item);
                            dataGridView1.Invoke((Action)(() =>
                            {
                                dataGridView1.Rows.Add(Path.GetFileName(img.FileName),
                                                       img.Format,
                                                       img.BaseWidth + "x" + img.BaseHeight,
                                                       img.Density,
                                                       img.Depth,
                                                       img.Compression,
                                                       img.TotalColors
                                                       );
                            }
                                                          ));
                        }catch
                        {
                        }
                    }
                }
                                      );
            }
        }
Example #5
0
        private static System.Drawing.Color GetTreeColor(TreeRow treeRow)
        {
            if (treeColors.ContainsKey(treeRow.Name))
            {
                return(treeColors[treeRow.Name]);
            }

            string treeTextureFile = string.Format("{0}\\zones\\trees\\{1}", Properties.Settings.Default.game_path, treeRow.LeafTexture);

            if (!File.Exists(treeTextureFile))
            {
                MainForm.Log(string.Format("Unable to get texture for tree {0}. Using default color.", treeRow.Name));
                return(System.Drawing.ColorTranslator.FromHtml("#5e683a"));
            }
            else
            {
                using (ImageMagick.MagickImage texture = new ImageMagick.MagickImage(treeTextureFile))
                {
                    texture.Resize(1, 1);
                    ImageMagick.Pixel pixel = texture.GetPixels().First();

                    System.Drawing.Color color = pixel.ToColor();
                    treeColors.Add(treeRow.Name, color);
                    return(color);
                }
            }
        }
Example #6
0
        private static FileEntry CalculateDiffImage(FileEntry oldImg, FileEntry newImg, double maxAllowedDiff, string errorMetric)
        {
            if (oldImg.Exists)
            {
#if ENABLE_IMAGE_MAGICK
                using (ImageMagick.MagickImage original = new ImageMagick.MagickImage()) {
                    original.LoadFromFileEntry(oldImg);
                    ImageMagick.ErrorMetric eM = EnumUtil.Parse <ImageMagick.ErrorMetric>(errorMetric);
                    var diff = original.Compare(newImg, eM, maxAllowedDiff);
                    if (diff != null)
                    {
                        return(diff);
                    }
                    else
                    {
                        newImg.CopyToV2(oldImg, replaceExisting: true);
                    }
                }
#else
                Log.d("AssertVisually.AssertNoVisualChange() skipped: ENABLE_IMAGE_MAGICK define not active, see instructions 'readme Image Magick Unity Installation Instructions.txt'");
#endif
            }
            else
            {
                newImg.CopyToV2(oldImg, replaceExisting: false);
            }
            return(null);
        }
Example #7
0
        //
        // Export
        //
        private void Button_Export_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog folderDialog = new FolderBrowserDialog();
                if (folderDialog.ShowDialog() != DialogResult.OK)
                {
                    UpdateStatus("No output folder selected", SystemIcons.Error);
                    return;
                }


                UpdateStatus("Preparing to export", 0, InputFiles.Count * 3);
                foreach (string file in InputFiles)
                {
                    // import
                    UpdateStatus($"Loading {file}", true);
                    using (ImageMagick.MagickImage img = new ImageMagick.MagickImage(file))
                    {
                        // convert
                        UpdateStatus($"Converting {file}", true);
                        if (checkBox_Resize.Checked)
                        {
                            img.Resize((int)numericUpDown_ResizeX.Value, (int)numericUpDown_ResizeY.Value);
                        }

                        if (checkBox_AlphaMask.Checked)
                        {
                            ImageMagick.IPixelCollection pixels = img.GetPixels();
                            int width  = img.Width;
                            int height = img.Height;
                            for (int y = 0; y < height; y++)
                            {
                                for (int x = 0; x < width; x++)
                                {
                                    ImageMagick.MagickColor pixelColor = pixels[x, y].ToColor();
                                    pixels[x, y].Set(new ushort[] { pixelColor.A, pixelColor.A, pixelColor.A, ushort.MaxValue });
                                }
                            }
                        }

                        // export
                        string exportPath = $@"{folderDialog.SelectedPath}{Path.DirectorySeparatorChar}{Path.GetFileName(file)}";
                        if (checkBox_ChangeFormat.Checked && comboBox_ExportFormat.SelectedItem != null)
                        {
                            exportPath = Path.ChangeExtension(exportPath, (comboBox_ExportFormat.SelectedItem as FormatComboBoxItem).Extension());
                        }
                        UpdateStatus($"Exporting \"{file}\"", true);
                        img.Write(exportPath);
                    }
                }

                UpdateStatus($"Exported {InputFiles.Count} files", 0);
            }
            catch (Exception ex)
            {
                UpdateStatus(ex.Message, SystemIcons.Error);
            }
        }
Example #8
0
        public static Bitmap LoadTGA(string filename)
        {
            Bitmap bit;

            using (var image = new ImageMagick.MagickImage(filename))
                bit = image.ToBitmap();

            return(bit);
        }
Example #9
0
        public static double TransparencyRate(this ImageMagick.MagickImage mi)
        {
            if (!mi.HasAlpha)
            {
                return(0);
            }
            var bytes = mi.Separate(ImageMagick.Channels.Alpha).First().GetPixels().GetValues();

            return((255 - bytes.Average(x => (double)x)) / 255);
        }
        public IActionResult Test1()
        {
            ImageMagick.MagickImage img = new ImageMagick.MagickImage(this.testfile);

            img.Scale(100, 100);

            byte[] result = img.ToByteArray();

            return(File(result, "image/jpeg"));
        }
Example #11
0
        public static void Run(ref byte[] decomp, int width)
        {
            BitmapData bmpDespeckle;

            if (width == 400)
            {
                bmpDespeckle = bmpDespeckleTop.LockBits(new Rectangle(0, 0, bmpDespeckleTop.Width, bmpDespeckleTop.Height), ImageLockMode.ReadWrite, bmpDespeckleTop.PixelFormat);
            }
            else
            {
                bmpDespeckle = bmpDespeckleBottom.LockBits(new Rectangle(0, 0, bmpDespeckleBottom.Width, bmpDespeckleBottom.Height), ImageLockMode.ReadWrite, bmpDespeckleBottom.PixelFormat);
            }

            Marshal.Copy(decomp, 0, bmpDespeckle.Scan0, decomp.Length);

            if ((Type)UseFilter == Type.AForgeLite)
            {
                // Very close to Magick and faster!
                AForgeFilter.KernelSize  = 3;
                AForgeFilter.ColorFactor = 10;

                AForgeFilter.ApplyInPlace(bmpDespeckle);

                // Don't make a new array for decomp, will make it slow.
                Marshal.Copy(bmpDespeckle.Scan0, decomp, 0, decomp.Length);
            }
            else if ((Type)UseFilter == Type.Magick)
            {
                //Magick is SLOWWWW
                magick = new ImageMagick.MagickImage();

                if (width == 400)
                {
                    magick.Read(bmpDespeckleTop);
                }
                else
                {
                    magick.Read(bmpDespeckleBottom);
                }

                magick.Despeckle();
                decomp = magick.ToByteArray(ImageMagick.MagickFormat.Bgr); //Use in place of bmpData.Scan0, bloody slow

                magick.Dispose();
            }

            if (width == 400)
            {
                bmpDespeckleTop.UnlockBits(bmpDespeckle);
            }
            else
            {
                bmpDespeckleBottom.UnlockBits(bmpDespeckle);
            }
        }
        public IActionResult Test2()
        {
            // This time set native dir
            ImageMagick.MagickNET.SetNativeLibraryDirectory(this.nativeidr);
            ImageMagick.MagickImage img = new ImageMagick.MagickImage(this.testfile);

            img.Scale(100, 100);

            byte[] result = img.ToByteArray();

            return(File(result, "image/jpeg"));
        }
Example #13
0
        public static Bitmap LoadTGA(Stream stream)
        {
            Bitmap bit;
            var    sett = new ImageMagick.MagickReadSettings()
            {
                Format = ImageMagick.MagickFormat.Tga
            };

            using (var image = new ImageMagick.MagickImage(stream.ToByteArray(), sett))
                bit = image.ToBitmap();

            return(bit);
        }
        private static string ExtractUrlFromQRImage(string qrCodeSetupImageUrl)
        {
            var headerLength = "data:image/png;base64,".Length;
            var rawImageData = qrCodeSetupImageUrl.Substring(headerLength, qrCodeSetupImageUrl.Length - headerLength);
            var imageData    = Convert.FromBase64String(rawImageData);

            var reader = new BarcodeReaderGeneric();

            reader.Options.PossibleFormats = new List <BarcodeFormat> {
                BarcodeFormat.QR_CODE
            };
            var image        = new ImageMagick.MagickImage(imageData);
            var wrappedImage = new ZXing.Magick.MagickImageLuminanceSource(image);

            return(reader.Decode(wrappedImage).Text);
        }
Example #15
0
 private bool AreVisuallyDifferent(Texture2D img1, Texture2D img2, Config config)
 {
     using (ImageMagick.MagickImage s1 = new ImageMagick.MagickImage()) {
         s1.Read(img1.EncodeToJPG(config.screenshotQuality));
         using (ImageMagick.MagickImage s2 = new ImageMagick.MagickImage()) {
             s2.Read(img2.EncodeToJPG(config.screenshotQuality));
             var errorMetric = EnumUtil.Parse <ImageMagick.ErrorMetric>(config.errorMetric);
             var diffValue   = s1.CompareV2(s2, errorMetric, out ImageMagick.MagickImage diffImg);
             if (diffValue < config.maxAllowedDiff)
             {
                 return(false);
             }
             diffImg.Dispose();
         }
     }
     return(true);
 }
 static void Main(string[] args)
 {
     // args[0] = path to analyse
     foreach (var file in Directory.GetFiles(args[0], "*.heic", SearchOption.AllDirectories))
     {
         using (ImageMagick.MagickImage image = new ImageMagick.MagickImage(file))
         {
             // I:\tmp\IMG_0935.heic
             var partial_output = file.Replace(".heic", ".jpg");
             var fileName       = partial_output.Split(new char[] { '\\' }).LastOrDefault();
             if (!string.IsNullOrEmpty(fileName))
             {
                 image.Write(string.Concat(args[1], @"\", fileName));
             }
         }
     }
     Console.ReadLine();
 }
Example #17
0
        /// <summary>
        /// Read and parse a sample file from disk, write it back out to a temp file, and verify metadata and properties via NTiff & ImageMagick. Returns hash of final output.
        /// </summary>
        /// <param name="src"></param>
        private static string CheckRewrite(string src)
        {
            var tiff = new Tiff(src);
            var temp = SamplesList.GetTemp();

            try
            {
                tiff.Save(temp);

                var newImg = new Tiff(temp);
                Assert.Equal(tiff.Images[0].Tags.Count, newImg.Images[0].Tags.Count);
                Assert.Equal(tiff.Images[0].Exif.Count, newImg.Images[0].Exif.Count);

                // Load source and temp in ImageMagick and compare properties
                var srcImg  = new ImageMagick.MagickImage(src);
                var tempImg = new ImageMagick.MagickImage(temp);

                var srcAttributes  = srcImg.AttributeNames;
                var tempAttributes = tempImg.AttributeNames;

                Assert.Equal(srcImg.Signature, tempImg.Signature);
                Assert.True(srcAttributes.SequenceEqual(tempAttributes));
                Assert.Equal(srcAttributes.Count(), tempAttributes.Count());

                foreach (var attr in srcAttributes)
                {
                    if (attr == "date:create" || attr == "date:modify")
                    {
                        continue;
                    }
                    Assert.Equal(srcImg.GetAttribute(attr), tempImg.GetAttribute(attr));
                }

                return(Convert.ToBase64String(System.Security.Cryptography.MD5.Create().ComputeHash(File.ReadAllBytes(temp))));
            }
            finally
            {
                SamplesList.Cleanup(temp);
            }
        }
Example #18
0
        /// <summary>
        /// Converte uma string de SVG para um vetor de bytes PNG
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static byte[] ConverteSvgParaPng(string value)
        {
            string path = System.IO.Path.GetTempPath() + "otimizacao" + DateTime.Now.Millisecond + ".svg";
            var    svg  = new System.IO.FileInfo(path);

            using (var sw = svg.CreateText())
            {
                sw.WriteLine(value);
            }

            using (var img = new ImageMagick.MagickImage(svg))
            {
                img.Format = ImageMagick.MagickFormat.Png;
                var arrImg = img.ToByteArray();

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }

                return(arrImg);
            }
        }
Example #19
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var filePath = openFileDialog1.FileName;
                try
                {
                    ImageMagick.MagickImage img = new ImageMagick.MagickImage(filePath);

                    dataGridView1.Rows.Add(Path.GetFileName(img.FileName),
                                           img.Format,
                                           img.BaseWidth + "x" + img.BaseHeight,
                                           img.Density,
                                           img.Depth,
                                           img.Compression,
                                           img.TotalColors
                                           );
                }
                catch
                {
                    MessageBox.Show("format not supported");
                }
            }
        }
Example #20
0
        public void SaveImage(ImageMagick.MagickImage magickImage, File file, string folder = "test")
        {
            Directory.CreateDirectory(file.Path + "\\" + folder + "\\");

            magickImage.Write(file.Path + "\\" + folder + "\\" + file.Name + "." + magickImage.Format.ToString().ToLower());
        }
Example #21
0
        static void Main(string[] args)
        {
            Console.Write("Host IP/Name: ");

            var host = Console.ReadLine();

            Console.Write("Host Port (or press enter for default 5900): ");

            int port;
            var userPort = Console.ReadLine();

            if (!int.TryParse(userPort, out port))
            {
                port = 5900;
            }

            Console.Write("VNC Password (or press enter to connect without a password): ");

            var stringBuilder = new StringBuilder();

            while (true)
            {
                var character = Console.ReadKey(true);
                if (character.Key == ConsoleKey.Enter)
                {
                    Console.WriteLine();
                    break;
                }

                if (character.Key == ConsoleKey.Backspace)
                {
                    if (stringBuilder.Length > 0)
                    {
                        Console.Write("\b\0\b");
                        stringBuilder.Length--;
                    }

                    continue;
                }

                Console.Write('*');
                stringBuilder.Append(character.KeyChar);
            }

            var password = stringBuilder.ToString();

            var client = new Client();

            if (!string.IsNullOrEmpty(password))
            {
                client.Password = password;
            }

            if (client.Connect(host, port))
            {
                if (!Directory.Exists("Images"))
                {
                    Directory.CreateDirectory("Images");
                }

                client.FrameBufferUpdated += (sender, e) =>
                {
                    Task.Run(() =>
                    {
                        var encodingStartTime = DateTime.Now;

                        using (var file = File.Open($@"Images\{e.UpdateTime:HH_mm_ss.fff}.png", FileMode.Create, FileAccess.Write, FileShare.Read))
                            using (var image = new ImageMagick.MagickImage(e.CurrentFrameBuffer, new ImageMagick.PixelReadSettings(client.SessionInfo.FrameBufferWidth, client.SessionInfo.FrameBufferHeight, ImageMagick.StorageType.Char, "BGRA")))
                            {
                                image.Format = ImageMagick.MagickFormat.Png32;

                                image.Alpha(ImageMagick.AlphaOption.Off);
                                image.Alpha(ImageMagick.AlphaOption.Remove);

                                image.Settings.SetDefine(ImageMagick.MagickFormat.Png, "compression-level", "2");
                                image.Settings.SetDefine(ImageMagick.MagickFormat.Png, "compression-filter", "2");

                                image.Write(file);

                                var encodingFinishTime = DateTime.Now;
                                Trace.TraceInformation($"Image encoding lasted {(encodingFinishTime - encodingStartTime).TotalSeconds} seconds, image size {file.Length:N} bytes, total time {(encodingFinishTime - e.UpdateTime).TotalSeconds} seconds at {encodingFinishTime:dd/MM/yyyy HH:mm:ss.fff}");
                            }
                    });
                };

                client.ServerCutText += (sender, e) => { System.Console.WriteLine(e.Text); };

                client.Bell += (sender, e) => { System.Media.SystemSounds.Beep.Play(); };

                client.FramebufferUpdateRequest(false, 0, 0, client.SessionInfo.FrameBufferWidth, client.SessionInfo.FrameBufferHeight);

                var updateInterval = TimeSpan.FromSeconds(1);

                Task.Run(() =>
                {
                    Task.Delay(updateInterval).Wait();

                    while (client.Connected)
                    {
                        var updateTime = DateTime.Now;
                        client.FramebufferUpdateRequest(true, 0, 0, client.SessionInfo.FrameBufferWidth, client.SessionInfo.FrameBufferHeight);
                        Task.Delay(TimeSpan.FromSeconds(Math.Max(updateInterval.TotalSeconds - (DateTime.Now - updateTime).TotalSeconds, 0))).Wait();
                    }
                });

                Task.Delay(TimeSpan.FromMinutes(1)).Wait();

                client.Close();
            }
        }
 public ImageMagick.MagickImage GetOffsetMap()
 {
     ImageMagick.MagickImage offsetmap = new ImageMagick.MagickImage(MpkWrapper.GetFileBytesFromMpk(this.m_datMpk, "offset.pcx"));
     return offsetmap;
 }
 public ImageMagick.MagickImage GetTerrainMap()
 {
     ImageMagick.MagickImage terrainmap = new ImageMagick.MagickImage(MpkWrapper.GetFileBytesFromMpk(this.m_datMpk, "terrain.pcx"));
     return terrainmap;
 }
 public ImageMagick.MagickImage GetTerrainMap()
 {
     ImageMagick.MagickImage terrainmap = new ImageMagick.MagickImage(MpkWrapper.GetFileBytesFromMpk(this.m_datMpk, "terrain.pcx"));
     return(terrainmap);
 }
        public ImageMagick.MagickImage GetWaterMap()
        {
            ImageMagick.MagickImage watermap = new ImageMagick.MagickImage(MpkWrapper.GetFileBytesFromMpk(this.m_datMpk, "water.pcx"));
            watermap.Resize(this.m_targetMapSize, this.m_targetMapSize);

            return watermap;
        }
 public ImageMagick.MagickImage GetOffsetMap()
 {
     ImageMagick.MagickImage offsetmap = new ImageMagick.MagickImage(MpkWrapper.GetFileBytesFromMpk(this.m_datMpk, "offset.pcx"));
     return(offsetmap);
 }
Example #27
0
        public async Task <IActionResult> DecodeFiles(ICollection <IFormFile> files)
        {
            ViewData["TextAreaResult"] = "No result.";

            foreach (var formFile in files)
            {
                if (formFile.Length > 0)
                {
                    using (var stream = formFile.OpenReadStream())
                    {
                        try
                        {
                            using (var image = SixLabors.ImageSharp.Image.Load(stream))
                            {
                                var reader = new ZXing.ImageSharp.BarcodeReader <SixLabors.ImageSharp.Rgba32>();
                                var result = reader.Decode(image);
                                ViewData["TextAreaResult"] = "ImageSharp: " + result?.Text;
                            }
                        }
                        catch (Exception exc)
                        {
                            ViewData["TextAreaResult"] = "ImageSharp: " + exc.Message;
                        }

                        try
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            using (var openCVImage = OpenCvSharp.Mat.FromStream(stream, OpenCvSharp.ImreadModes.GrayScale))
                            {
                                var openCVReader = new ZXing.OpenCV.BarcodeReader();
                                var openCVResult = openCVReader.Decode(openCVImage);
                                ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "OpenCV: " + openCVResult?.Text;
                            }
                        }
                        catch (Exception exc)
                        {
                            ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "OpenCV: " + exc.Message;
                        }

                        try
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            using (var coreCompatImage = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(stream))
                            {
                                var coreCompatReader = new ZXing.CoreCompat.System.Drawing.BarcodeReader();
                                var coreCompatResult = coreCompatReader.Decode(coreCompatImage);
                                ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "CoreCompat.System.Drawing: " + coreCompatResult?.Text;
                            }
                        }
                        catch (Exception exc)
                        {
                            ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "CoreCompat.System.Drawing: " + exc.Message;
                        }

                        try
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            using (var magickImage = new ImageMagick.MagickImage(stream))
                            {
                                var magickReader = new ZXing.Magick.BarcodeReader();
                                var magickResult = magickReader.Decode(magickImage);
                                ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "Magick: " + magickResult?.Text;
                            }
                        }
                        catch (Exception exc)
                        {
                            ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "Magick: " + exc.Message;
                        }

                        try
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            using (var skiaImage = SkiaSharp.SKBitmap.Decode(stream))
                            {
                                var skiaReader = new ZXing.SkiaSharp.BarcodeReader();
                                var skiaResult = skiaReader.Decode(skiaImage);
                                ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "SkiaSharp: " + skiaResult?.Text;
                            }
                        }
                        catch (Exception exc)
                        {
                            ViewData["TextAreaResult"] = ViewData["TextAreaResult"] + "SkiaSharp: " + exc.Message;
                        }
                    }
                }
            }

            ViewData["Message"] = "Your decoding page.";

            return(View("Decode"));
        }
Example #28
0
        private static System.Drawing.Color GetTreeColor(TreeRow treeRow)
        {
            if (treeColors.ContainsKey(treeRow.Name)) return treeColors[treeRow.Name];

            string treeTextureFile = string.Format("{0}\\zones\\trees\\{1}", Properties.Settings.Default.game_path, treeRow.LeafTexture);
            if (!File.Exists(treeTextureFile))
            {
                MainForm.Log(string.Format("Unable to get texture for tree {0}. Using default color.", treeRow.Name));
                return System.Drawing.ColorTranslator.FromHtml("#5e683a");
            }
            else
            {
                using (ImageMagick.MagickImage texture = new ImageMagick.MagickImage(treeTextureFile))
                {
                    texture.Resize(1, 1);
                    ImageMagick.Pixel pixel = texture.GetReadOnlyPixels(0, 0, 1, 1).First();

                    System.Drawing.Color color = pixel.ToColor();
                    treeColors.Add(treeRow.Name, color);
                    return color;
                }
            }
        }