Example #1
0
        public async Task <UploadResult> Upload(IBitmapImage Image, ImageFormats Format, Action <int> Progress)
        {
            using var w = new WebClient { Proxy = _proxySettings.GetWebProxy() };
            if (Progress != null)
            {
                w.UploadProgressChanged += (S, E) => Progress(E.ProgressPercentage);
            }

            w.Headers.Add("Authorization", await GetAuthorizationHeader());

            NameValueCollection values;

            using (var ms = new MemoryStream())
            {
                Image.Save(ms, Format);

                values = new NameValueCollection
                {
                    { "image", Convert.ToBase64String(ms.ToArray()) }
                };
            }

            var uploadResponse = await UploadValuesAsync <ImgurUploadResponse>(w, "https://api.imgur.com/3/upload.json", values);

            if (!uploadResponse.Success)
            {
                throw new Exception("Response indicates Failure");
            }

            return(new UploadResult
            {
                Url = uploadResponse.Data.Link,
                DeleteLink = $"https://api.imgur.com/3/image/{uploadResponse.Data.DeleteHash}"
            });
        }
Example #2
0
        public Task Save(IBitmapImage Image, ImageFormats Format, string FileName)
        {
            try
            {
                var extension = Format.ToString().ToLower();

                var fileName = _settings.GetFileName(extension, FileName);

                Image.Save(fileName, Format);

                _recentList.Add(new FileRecentItem(fileName, RecentFileType.Image));

                // Copy path to clipboard only when clipboard writer is off
                if (_settings.CopyOutPathToClipboard && !ServiceProvider.Get <ClipboardWriter>().Active)
                {
                    fileName.WriteToClipboard();
                }

                _systemTray.ShowScreenShotNotification(fileName);
            }
            catch (Exception e)
            {
                _messageProvider.ShowException(e, _loc.NotSaved);
            }

            return(Task.CompletedTask);
        }
Example #3
0
        public void SetImage(IBitmapImage Bmp)
        {
            using var pngStream = new MemoryStream();
            Bmp.Save(pngStream, ImageFormats.Png);
            var pngClipboardData = new DataObject("PNG", pngStream);

            using var whiteS = new Bitmap(Bmp.Width, Bmp.Height, PixelFormat.Format24bppRgb);
            Image drawingImg;

            if (Bmp is DrawingImage drawingImage)
            {
                drawingImg = drawingImage.Image;
            }
            else
            {
                drawingImg = Image.FromStream(pngStream);
            }

            using (var graphics = Graphics.FromImage(whiteS))
            {
                graphics.Clear(Color.White);
                graphics.DrawImage(drawingImg, 0, 0, Bmp.Width, Bmp.Height);
            }

            // Add fallback for applications that don't support PNG from clipboard (eg. Photoshop or Paint)
            pngClipboardData.SetData(DataFormats.Bitmap, whiteS);

            Clipboard.Clear();
            Clipboard.SetDataObject(pngClipboardData, true);
        }
Example #4
0
        public Task Save(IBitmapImage Image, ImageFormats Format, string FileName)
        {
            if (!File.Exists(FileName))
            {
                Image.Save(FileName, Format);
            }

            var winserv = ServiceProvider.Get <IMainWindow>();

            winserv.EditImage(FileName);

            return(Task.CompletedTask);
        }
Example #5
0
        public Task Save(IBitmapImage image, ImageFormats format, string fileName)
        {
            using (var stream = new MemoryStream())
            {
                image.Save(stream, ImageFormats.Png);

                var decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);

                var win = new ImageEditorWindow();

                win.Open(decoder.Frames[0]);

                win.Show();
            }

            return(Task.CompletedTask);
        }
Example #6
0
        public static string RenderTemplate(string imagePath)

        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            Pulse.Extensions.RenderOptions ro = new Pulse.Extensions.RenderOptions();
            ro.Height = 300;
            ro.Width  = 300;
            myImage   = PulseEmbComExtensions.Render(myDesign, ro);
            myImage.Save(imagePath, ImageTypes.itAuto);
            stopWatch.Stop();
            TimeSpan ts          = stopWatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                 ts.Hours, ts.Minutes, ts.Seconds,
                                                 ts.Milliseconds / 10);

            return(elapsedTime);
        }
        static void Main(string[] args)
        {
            IApplication PulseID = new Pulse.Application();

            try
            {
                IEmbDesign myDesign = PulseID.OpenDesign("C:\\Temp\\Eagle2.pxf", FileTypes.ftAuto, OpenTypes.otDefault, "Tajima");
                try
                {
                    IBitmapImage myImage = PulseID.NewImage(300, 300);
                    try
                    {
                        myDesign.Render(myImage, 0, 0, 300, 300);
                        myImage.Save("C:\\Temp\\myImage.png", ImageTypes.itAuto);

                        PrintThreadChartNames(PulseID.ThreadCharts);

                        INeedleSequence designNeedleSequence = myDesign.NeedleSequence;
                        try
                        {
                            IThreadPalette designThreadPalette = myDesign.ThreadPalette;
                            // Get the thread palette information for the design.
                            try
                            {
                                // find the needle that is used for each color in the design.  Needle sequence is zero based 0=needle 1
                                for (int i = 0; i < designNeedleSequence.Count; i++)
                                {
                                    int             needle     = designNeedleSequence[i];
                                    IThreadProperty threadInfo = designThreadPalette[needle];

                                    Console.WriteLine("Manufacturer= {0} Name= {1} Code= {2} R= {3} G= {4} B= {5}", threadInfo.Manufacturer, threadInfo.Name, threadInfo.Code, threadInfo.Red, threadInfo.Green, threadInfo.Blue);
                                }
                                UpdateThreadColor(PulseID.ThreadCharts, myDesign, 0, "Madeira Classic Rayon 40", "1002");
                                UpdateThreadColor(PulseID.ThreadCharts, myDesign, 1, "Madeira Classic Rayon 40", "1000");


                                Console.WriteLine();
                                Console.WriteLine("New Thread Sequence");
                                Console.WriteLine("------------------------------" +
                                                  "");

                                // Get the thread palette information for the design.

                                // find the needle that is used for each color in the design.  Needle sequence is zero based 0=needle 1
                                for (int i = 0; i < designNeedleSequence.Count; i++)
                                {
                                    int             needle     = designNeedleSequence[i];
                                    IThreadProperty threadInfo = designThreadPalette[needle];

                                    Console.WriteLine("Manufacturer= {0} Name= {1} Code= {2} R= {3} G= {4} B= {5}", threadInfo.Manufacturer, threadInfo.Name, threadInfo.Code, threadInfo.Red, threadInfo.Green, threadInfo.Blue);
                                }

                                Console.WriteLine("Done");

                                ;

                                Console.ReadLine();

                                myDesign.Render(myImage, 0, 0, 300, 300);
                                myImage.Save("C:\\Temp\\myNewImage.png", ImageTypes.itAuto);
                                myDesign.Save("C:\\Temp\\NewDesign.pxf", FileTypes.ftAuto);
                            }
                            finally
                            {
                                Marshal.ReleaseComObject(designThreadPalette);
                            }
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(designNeedleSequence);
                        }
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(myImage);
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(myDesign);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(PulseID);
            }
        }