public Save ( Stream stream ) : |
||
stream | Stream |
/// The |
리턴 |
private static async Task<Tuple<Stream, Image>> ImageResize(string imageString, int quality, Func<System.Drawing.Image, Size> sizeCalculation) { var photoBytes = Base64ImageDataToByteArray(imageString); var format = new JpegFormat(); using (MemoryStream inStream = new MemoryStream(photoBytes)) { MemoryStream outStream = new MemoryStream(); int width; int height; using (ImageFactory imageFactory = new ImageFactory()) { imageFactory.Load(inStream) .Resize(sizeCalculation(imageFactory.Image)) .Format(format) .Quality(quality); System.Drawing.Image image = imageFactory.Image; width = image.Width; height = image.Height; imageFactory.Save(outStream); } return new Tuple<Stream, Models.Image>(outStream, new Image("bloblstorage", width, height)); // Do something with the stream. } }
/// <summary> /// Convert a file to PictureContainer /// </summary> /// <param name="fileIn"></param> /// <param name="size"></param> /// <param name="format"></param> /// <returns></returns> private static PictureContainer Convert(string fileIn, PresetSize size, ISupportedImageFormat format) { var filename = Path.GetFileNameWithoutExtension(fileIn); // Generate Url var id = Guid.NewGuid(); var path = string.Format(@"/Temp/{0}/{1}_{2}x{3}.{4}", id, filename, size.Size.Width, size.Size.Height, format.DefaultExtension); using (var imageFactory = new ImageFactory(true)) { try { // Load, resize, set the format and save an image. imageFactory.Load(fileIn) .Resize(size.Size) .Format(format); imageFactory.Save(path); if (!File.Exists(path)) throw new FileNotFoundException("File not found"); var pc = new PictureContainer { PresetSize = size, FilePath = path }; return pc; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return null; } } }
// GET: Media public ActionResult Cache(String slug, String format, String filename) { String cacheFilename = Server.MapPath(String.Format("~/App_Data/media/{0}/{1}/{2}", slug, format, filename)); String remoteFilename = String.Format("https://robertsspaceindustries.com/media/{0}/{1}/{2}", slug, "source", filename); if (!System.IO.File.Exists(cacheFilename)) { if (!System.IO.Directory.Exists(Path.GetDirectoryName(cacheFilename))) System.IO.Directory.CreateDirectory(Path.GetDirectoryName(cacheFilename)); using (WebClient client = new WebClient()) { using (Stream stream = client.OpenRead(remoteFilename)) { using (MemoryStream inStream = new MemoryStream()) { stream.CopyTo(inStream); using (ImageFactory factory = new ImageFactory()) { factory.Load(inStream); String[] parts = format.Split('x'); if (parts.Length != 2) { parts = new String[] { "800", "600" }; } factory.Constrain(new System.Drawing.Size { Height = parts[1].ToInt32(600), Width = parts[0].ToInt32(800) }); // , new System.Drawing.Point // { // X = factory.Image.Width / 2, // Y = factory.Image.Height / 2 // }); if (Path.GetExtension(cacheFilename) == "jpg") { using (FileStream outStream = new FileStream(cacheFilename, FileMode.Create)) { factory.Optimize(outStream); } } else { factory.Save(cacheFilename); } } } } } } String contentType = MimeMapping.GetMimeMapping(cacheFilename); this.Response.Cache.SetCacheability(HttpCacheability.Public); this.Response.Cache.SetExpires(DateTime.Today.AddDays(7)); this.Response.Cache.SetMaxAge(TimeSpan.FromHours(168)); return File(cacheFilename, contentType); }
private string SaveLargeImage(byte[] bytes, string fileName) { using (MemoryStream inStream = new MemoryStream(bytes)) { using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory()) { // Load, resize, set the format and quality and save an image. imageFactory.Load(inStream); int width = imageFactory.Image.Size.Width; int height = imageFactory.Image.Size.Height; if (width > 1600) { int newHeight = (int)((1600 / (double)width) * height); imageFactory.Resize(new Size(1600, newHeight)); imageFactory.Format(ImageFormat.Jpeg); imageFactory.Quality(80); imageFactory.Save(outStream); } else if (height > 1600) { int newWidth = (int)((1600 / (double)height) * width); imageFactory.Resize(new Size(newWidth, 1600)); imageFactory.Format(ImageFormat.Jpeg); imageFactory.Quality(80); imageFactory.Save(outStream); } else { imageFactory.Save(outStream); } } outStream.Position = 0; var resizedResult = this._fileStorage.UploadFile(outStream, fileName, "products/"); return resizedResult.Uri.ToString(); } } }
private string SaveThumbnail(byte[] bytes, string fileName) { using (MemoryStream inStream = new MemoryStream(bytes)) { using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory()) { // Load, resize, set the format and quality and save an image. imageFactory.Load(inStream); imageFactory.Resize(new Size(200, 0)); imageFactory.Format(ImageFormat.Jpeg); imageFactory.Quality(80); imageFactory.Save(outStream); } outStream.Position = 0; var thumbnailResult = this._fileStorage.UploadFile(outStream, "thumb-" + fileName, "products/"); return thumbnailResult.Uri.ToString(); } } }
private void CaptureLayer() { SetFlashFill(captureIndex); flashStoryboard.Begin(this); switch (captureIndex) { case 0: capture1Storyboard.Begin(this); break; case 1: capture2Storyboard.Begin(this); break; case 2: capture3Storyboard.Begin(this); break; default: break; } RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)CompositeImage.ActualWidth, (int)CompositeImage.ActualHeight, 96.0, 96.0, PixelFormats.Pbgra32); DrawingVisual dv = new DrawingVisual(); using (DrawingContext dc = dv.RenderOpen()) { VisualBrush brush = new VisualBrush(CompositeImage); dc.DrawRectangle(brush, null, new Rect(new System.Windows.Point(), new System.Windows.Size(CompositeImage.ActualWidth, CompositeImage.ActualHeight))); } renderBitmap.Render(dv); byte[] encoded; using (MemoryStream stream = new MemoryStream()) { var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); encoder.Save(stream); encoded = stream.ToArray(); } BitmapImage processed = new BitmapImage(); double opacity = 1; using (MemoryStream stream = new MemoryStream()) { using (ImageProcessor.ImageFactory imageFactory = new ImageProcessor.ImageFactory(false)) { imageFactory.Load(encoded); imageFactory.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.BlackWhite); switch (captureIndex) { case 0: break; case 1: imageFactory.Tint(System.Drawing.Color.Magenta); opacity = .4; break; case 2: imageFactory.Tint(System.Drawing.Color.Cyan); opacity = .3; break; case 3: imageFactory.Tint(System.Drawing.Color.Yellow); opacity = .2; break; default: break; } imageFactory.Save(stream); } processed.BeginInit(); processed.CacheOption = BitmapCacheOption.OnLoad; processed.StreamSource = stream; processed.EndInit(); } System.Windows.Controls.Image image = new System.Windows.Controls.Image() { Source = processed, Stretch = Stretch.None, Opacity = opacity }; CompositeLayers.Children.Add(image); }
private void goGenerateProcessesFriendship() { int artOfficial = 0; foreach (var theProcess in Process.GetProcesses()) { if (theProcess.MainWindowTitle != "" && theProcess.MainWindowTitle != "Space") { artOfficial++; } } if (artOfficial != currentCountProc) { spaceForProcesses.Controls.Clear(); int procCount = 0; foreach (var theProcess in Process.GetProcesses()) { if (procCount != 0 && procCount != 4) { if ((theProcess.MainWindowTitle != "" && theProcess.Modules[0].FileName != "ProjectSnowshoes.exe") && theProcess.MainWindowHandle != null) { foreach (var h in getHandles(theProcess)) { if (IsWindowVisible(h)) { PictureBox hmGreatJobFantasticAmazing = new PictureBox(); StringBuilder sb = new StringBuilder(GetWindowTextLength(h) + 1); GetWindowText(h, sb, sb.Capacity); hmGreatJobFantasticAmazing.Margin = new Padding(6, 0, 6, 0); hmGreatJobFantasticAmazing.Visible = true; hmGreatJobFantasticAmazing.SizeMode = PictureBoxSizeMode.CenterImage; hmGreatJobFantasticAmazing.BackgroundImageLayout = ImageLayout.Zoom; Icon.ExtractAssociatedIcon(theProcess.Modules[0].FileName).ToBitmap().Save(@"C:\ProjectSnowshoes\temptaskico.png"); ImageFactory grayify = new ImageFactory(); grayify.Load(@"C:\ProjectSnowshoes\temptaskico.png"); Size sizeeeee = new System.Drawing.Size(); sizeeeee.Height = 20; sizeeeee.Width = 20; ImageProcessor.Imaging.ResizeLayer reLay = new ImageProcessor.Imaging.ResizeLayer(sizeeeee); grayify.Resize(reLay); hmGreatJobFantasticAmazing.Image = grayify.Image; hmGreatJobFantasticAmazing.Click += (sender, args) => { ShowWindow(theProcess.MainWindowHandle, 5); ShowWindow(theProcess.MainWindowHandle, 9); }; hmGreatJobFantasticAmazing.MouseHover += (sender, args) => { Properties.Settings.Default.stayHere = true; Properties.Settings.Default.Save(); int recordNao = hmGreatJobFantasticAmazing.Left; hmGreatJobFantasticAmazing.Image.Save(@"C:\ProjectSnowshoes\TheyNeedToKeepOriginalAlbums.png"); Size sizeeeeeA = new System.Drawing.Size(); sizeeeeeA.Height = 100; sizeeeeeA.Width = 100; ImageProcessor.Imaging.ResizeLayer reLayA = new ImageProcessor.Imaging.ResizeLayer(sizeeeeeA); ImageProcessor.Imaging.GaussianLayer gauLay = new ImageProcessor.Imaging.GaussianLayer(); gauLay.Sigma = 2; gauLay.Threshold = 10; gauLay.Size = 20; ImageFactory backify = new ImageFactory(); backify.Load(@"C:\ProjectSnowshoes\TheyNeedToKeepOriginalAlbums.png"); backify.Brightness(-30); backify.Resize(reLayA); backify.GaussianBlur(gauLay); ImageProcessor.Imaging.CropLayer notAsLongAsOriginalName = new ImageProcessor.Imaging.CropLayer(90, 0, 0, 0, ImageProcessor.Imaging.CropMode.Percentage); backify.Crop(new Rectangle(25, (100 - this.Height) / 2, 50, this.Height)); hmGreatJobFantasticAmazing.BackgroundImage = backify.Image; grayify.Save(@"C:\ProjectSnowshoes\TheyStillNeedToKeepOriginalAlbums.png"); ImageFactory grayifyA = new ImageFactory(); grayifyA.Load(@"C:\ProjectSnowshoes\TheyStillNeedToKeepOriginalAlbums.png"); grayifyA.Saturation(44); grayifyA.Brightness(42); hmGreatJobFantasticAmazing.Image = grayifyA.Image; // Yeahhhhhhhhh I'm going to have to do this another way // panel1.Controls.Add(areYouSeriouslyStillDoingThisLetItGo); // Oh // I can just make another form to draw over and go have turnips with parameters // Also credits to Microsoft Word's "Sentence Case" option as this came out in all caps originally // Measuring string turnt-up-edness was guided by an answer on Stack Overflow by Tom Anderson. String keepThisShortWeNeedToOptimize = sb.ToString().Replace("&", "&&"); Graphics heyGuessWhatGraphicsYeahThatsRight = Graphics.FromImage(new Bitmap(1, 1)); SizeF sure = heyGuessWhatGraphicsYeahThatsRight.MeasureString(keepThisShortWeNeedToOptimize, new System.Drawing.Font(Properties.Settings.Default.fontsOfScience[Properties.Settings.Default.whoIsThisCrazyDoge], 14, FontStyle.Regular, GraphicsUnit.Point)); Size sureAgain = sure.ToSize(); int recordThatJim; if (sureAgain.Width >= 300) { recordThatJim = sureAgain.Width + 10; } else { recordThatJim = 300; } CanWeMakeAHoverFormLikeThisIsThisLegal notAsLongInstanceName = new CanWeMakeAHoverFormLikeThisIsThisLegal(recordNao + 150, this.Height, recordThatJim, keepThisShortWeNeedToOptimize); notAsLongInstanceName.Show(); notAsLongInstanceName.BringToFront(); //hmGreatJobFantasticAmazing.BringToFront(); //panel1.Controls.Add(hmGreatJobFantasticAmazing); //hmGreatJobFantasticAmazing.Top = this.Top - 40; //hmGreatJobFantasticAmazing.Left = recordNao + 150; //hmGreatJobFantasticAmazing.BringToFront(); //hmGreatJobFantasticAmazing.Invalidate(); /*hmGreatJobFantasticAmazing.Height = 100; hmGreatJobFantasticAmazing.Width = 100;*/ }; hmGreatJobFantasticAmazing.MouseLeave += (sender, args) => { /*hmGreatJobFantasticAmazing.ImageAlign = ContentAlignment.MiddleCenter; hmGreatJobFantasticAmazing.AutoEllipsis = false; hmGreatJobFantasticAmazing.Width = 40; hmGreatJobFantasticAmazing.BackColor = Color.Transparent; //hmGreatJobFantasticAmazing.Font = new System.Drawing.Font(Properties.Settings.Default.fontsOfScience[Properties.Settings.Default.whoIsThisCrazyDoge], 14, FontStyle.Regular); //hmGreatJobFantasticAmazing.ForeColor = Color.White; hmGreatJobFantasticAmazing.TextAlign = ContentAlignment.MiddleLeft; hmGreatJobFantasticAmazing.Text = "";*/ try { Application.OpenForms["CanWeMakeAHoverFormLikeThisIsThisLegal"].Close(); } catch (Exception exTurnip) { } hmGreatJobFantasticAmazing.BackgroundImage = null; hmGreatJobFantasticAmazing.Invalidate(); Properties.Settings.Default.stayHere = false; Properties.Settings.Default.Save(); hmGreatJobFantasticAmazing.Image = grayify.Image; }; //openFileToolTip.SetToolTip(hmGreatJobFantasticAmazing, theProcess.MainWindowTitle); //hmGreatJobFantasticAmazing.BackgroundImage = Icon.ExtractAssociatedIcon(theProcess.Modules[0].FileName).ToBitmap(); hmGreatJobFantasticAmazing.Height = this.Height; hmGreatJobFantasticAmazing.Width = 50; spaceForProcesses.Controls.Add(hmGreatJobFantasticAmazing); } } } } procCount++; } } currentCountProc = artOfficial; }