/// <summary> /// save the given bitmap to a file in the given format (jpeg/png) /// </summary> private static void Save(byte[] bmp, int image_width, int image_height, String filename, String format) { Gdk.Pixbuf buffer = createPixbuf(image_width, image_height); setBitmap(bmp, buffer); buffer.Save(filename, format); }
/// <summary> /// Take screenshot and save it as PNG image to defined directory /// </summary> public void takeSnapShot() { Gdk.Window window = Gdk.Global.DefaultRootWindow; if (window != null) { Gdk.Pixbuf pixBuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, window.Screen.Width, window.Screen.Height); pixBuf.GetFromDrawable(window, Gdk.Colormap.System, 0, 0, 0, 0, window.Screen.Width, window.Screen.Height); var now = DateTime.Now; // 2012-12-28 var dayPath = String.Format("{0:0000}-{1:00}-{2:00}", now.Year, now.Month, now.Day); // 235911,213 var fileName = String.Format("{0:00}{1:00}{2:00},{3}", now.Hour, now.Minute, now.Second, now.Millisecond); var savePath = settings.directory + "\\" + dayPath; if (!Directory.Exists(savePath)) { // Generate directory Directory.CreateDirectory(savePath); } savePath += "\\" + fileName + ".png"; // Save screenshot pixBuf.Save(savePath, "png"); lastFileName = savePath; } }
public static string CreateFile(string name, int size) { using (Gdk.Pixbuf test = new Gdk.Pixbuf(null, "f-spot-32.png")) { using (Gdk.Pixbuf tmp = test.ScaleSimple(size, size, Gdk.InterpType.Bilinear)) { string path = System.IO.Path.GetTempPath(); path = System.IO.Path.Combine(path, name); Console.WriteLine(path); string extension = System.IO.Path.GetExtension(path); string type = "null"; switch (extension.ToLower()) { case ".jpg": case ".jpeg": type = "jpeg"; break; case ".png": type = "png"; break; case ".tiff": type = "tiff"; break; } tmp.Save(path, type); return(path); } } }
public string CreateFile(string name, int size) { using (Gdk.Pixbuf test = new Gdk.Pixbuf(null, "f-spot-32.png")) { using (Gdk.Pixbuf tmp = test.ScaleSimple(size, size, Gdk.InterpType.Nearest)) { string path = System.IO.Path.GetTempPath(); path = System.IO.Path.Combine(path, name); Console.WriteLine(path); tmp.Save(path, Path.GetExtension(path).TrimStart(new char [] { '.' })); return(path); } } }
private bool AlbumArtExists(TrackInfo currentTrack) { image = artwork_manager_service.LookupPixbuf(current_track.ArtworkId); if (image == null || !image.Save(albumWallpaper, "png")) { return(false); } else { return(true); } }
/// <summary> /// Exports image in PNG format. /// </summary> static void ExportAsPngImage(ImageInfo image, string path) { int width = image.ImageObject.Elements.GetInteger(PdfImage.Keys.Width); int height = image.ImageObject.Elements.GetInteger(PdfImage.Keys.Height); try { byte [] data = image.ImageObject.Stream.UnfilteredValue; using (var pixbuf = new Gdk.Pixbuf(data, Gdk.Colorspace.Rgb, false, 8, width, height, width * 3)) { pixbuf.Save(path, "png"); } } catch (Exception e) { Hyena.Log.Exception("Unable to load PNG from embedded PDF object", e); } }
// Not tested in a while, probably wrong channel order. private unsafe void DumpDebugImage(byte[] image, int sizeX, int sizeY, int frameIndex) { #if FAMISTUDIO_LINUX || FAMISTUDIO_MACOS var pb = new Gdk.Pixbuf(image, true, 8, sizeX, sizeY, sizeX * 4); pb.Save($"/home/mat/Downloads/frame_{frameIndex:D4}.png", "png"); #else fixed(byte *vp = &image[0]) { var b = new Bitmap(sizeX, sizeY, sizeX * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, new IntPtr(vp)); b.Save($"d:\\dump\\pr\\frame_{frameIndex:D4}.png"); } #endif }
public void SaveTagIcon(Tag tag) { Gdk.Pixbuf icon = tag.Icon; Gdk.Pixbuf scaled = null; if (icon.Height != 52 || icon.Width != 52) { scaled = icon.ScaleSimple(52, 52, Gdk.InterpType.Bilinear); } else { scaled = icon.Copy(); } scaled.Save(SubdirPath("tags", TagName(tag)), "png"); scaled.Dispose(); }
private static string createIcon(string svgPath) { string iconPath = getPathFor(".png", svgPath); Gdk.Pixbuf icon = Rsvg.Pixbuf.FromFileAtMaxSize(svgPath, 255, 255); if (icon != null) { if (File.Exists(iconPath)) { File.Delete(iconPath); } icon.Save(iconPath, "png"); } return(iconPath); }
public bool Save(string DestinationThemeDir, bool OverwriteFile, bool CreateSymlinks) { char Sep = Path.DirectorySeparatorChar; string newpath = DestinationThemeDir + Sep + GetSizeDir() + Sep + contextToStr(Context) + Sep; string newfilename = newpath + FdoName + Path.GetExtension(Filename); try{ if (Context == ContextType.cNone) { Context = guessContextFromStr(Path.GetFullPath(Filename)); Console.WriteLine("Guessing the icon " + Filename + ", belongs probably to " + Context.ToString()); } if (!Directory.Exists(newpath)) { Directory.CreateDirectory(Path.GetFullPath(newpath)); } //Console.WriteLine("Old: "+Filename+",New: "+ newfilename); if (Filename == "") { Pixbuf.Save(newfilename, CUtility.ImageTypeToStr(Type)); } else { File.Copy(Filename, newfilename, OverwriteFile); //File.Move } //Has to be included in the icon-class if this unit will be the base of a icon-generator-app //For now, it's ok to copy it while saving string IconFile = Path.ChangeExtension(Filename, "icon"); if (File.Exists(IconFile)) { File.Copy(IconFile, Path.ChangeExtension(newfilename, "icon"), OverwriteFile); //File.Move } //for max compatibility if (CreateSymlinks) { foreach (string link in LinkedNames) { CUtility.Execute("ln", "-s " + newfilename + " " + newpath + link + Path.GetExtension(Filename)); } } } catch (Exception e) { Console.WriteLine("Warning: " + e.Message); } return(true); }
protected string CreateImageThumbnail(System.Drawing.Image Image, string Directory, int Width, int Height) { if (!System.IO.Directory.Exists(Directory)) { System.IO.Directory.CreateDirectory(Directory); } string shortname = Guid.NewGuid().ToString() + ".png"; string filename = System.IO.Path.Combine(Directory, shortname); using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { Image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); stream.Position = 0; using (Gdk.Pixbuf img = new Gdk.Pixbuf(stream)) { using (Gdk.Pixbuf pixbuf = img.ScaleSimple(Width, Height, Gdk.InterpType.Bilinear)) { pixbuf.Save(filename, "png"); // doc says "jpeg" is supported, but its not... return(shortname); } } } }
/// <summary> /// Exports image in PNG format. /// </summary> static void ExportAsPngImage (ImageInfo image, string path) { int width = image.ImageObject.Elements.GetInteger (PdfImage.Keys.Width); int height = image.ImageObject.Elements.GetInteger (PdfImage.Keys.Height); try { byte [] data = image.ImageObject.Stream.UnfilteredValue; using (var pixbuf = new Gdk.Pixbuf (data, Gdk.Colorspace.Rgb, false, 8, width, height, width*3)) { pixbuf.Save (path, "png"); } } catch (Exception e) { Hyena.Log.Exception ("Unable to load PNG from embedded PDF object", e); } }
// requires: nothing // effects: Saves the image with the given filename. // Returns true if successful; false otehrwise. public bool SaveCompositeImage(string filename) { return(_compImage.Save(filename, "png")); }
public void Save () { Gdk.Pixbuf test = new Gdk.Pixbuf (null, "f-spot-32.png"); string path = ImageFile.TempPath ("joe.png"); test.Save (path, "png"); PngFile pimg = new PngFile (path); string desc = "this is a png test"; string desc2 = "\000xa9 Novell Inc."; pimg.SetDescription (desc); using (Stream stream = File.OpenWrite (path)) { pimg.Save (stream); } PngFile mod = new PngFile (path); Assert.AreEqual (mod.Orientation, PixbufOrientation.TopLeft); Assert.AreEqual (mod.Description, desc); pimg.SetDescription (desc2); using (Stream stream = File.OpenWrite (path)) { pimg.Save (stream); } mod = new PngFile (path); Assert.AreEqual (mod.Description, desc2); File.Delete (path); }
private bool AlbumArtExists(TrackInfo currentTrack) { image = artwork_manager_service.LookupPixbuf(current_track.ArtworkId); if (image == null || !image.Save(albumWallpaper, "png")) return false; else return true; }
/// <summary> /// Take screenshot and save it as PNG image to defined directory /// </summary> public void takeSnapShot() { Gdk.Window window = Gdk.Global.DefaultRootWindow; if (window != null) { Gdk.Pixbuf pixBuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, window.Screen.Width, window.Screen.Height); pixBuf.GetFromDrawable(window, Gdk.Colormap.System, 0, 0, 0, 0, window.Screen.Width, window.Screen.Height); var now = DateTime.Now; // 2012-12-28 var dayPath = String.Format("{0:0000}-{1:00}-{2:00}", now.Year, now.Month, now.Day); // 235911,213 var fileName = String.Format("{0:00}{1:00}{2:00},{3}", now.Hour, now.Minute, now.Second, now.Millisecond); var savePath = settings.directory + "\\" + dayPath; if(!Directory.Exists(savePath)) { // Generate directory Directory.CreateDirectory(savePath); } savePath += "\\" + fileName + ".png"; // Save screenshot pixBuf.Save(savePath, "png"); lastFileName = savePath; } }