public static byte[] ToBytes(ArtworkFormat format, Gdk.Pixbuf pixbuf, out short horizontalPadding, out short verticalPadding) { horizontalPadding = 0; verticalPadding = 0; bool disposePixbuf = false; if (format.Rotation > 0) { pixbuf = Rotate(pixbuf, format.Rotation); disposePixbuf = true; } if (pixbuf.Height != format.Height || pixbuf.Width != format.Width) { int padX, padY; Gdk.Pixbuf scaled = Scale(pixbuf, format.Width, format.Height, out padX, out padY); horizontalPadding = (short)padX; verticalPadding = (short)padY; if (disposePixbuf) { pixbuf.Dispose(); } pixbuf = scaled; disposePixbuf = true; } byte[] data = null; switch (format.PixelFormat) { case PixelFormat.Rgb565: data = PackRgb565(pixbuf, false); break; case PixelFormat.Rgb565BE: data = PackRgb565(pixbuf, true); break; case PixelFormat.IYUV: data = PackIYUV(pixbuf); break; default: throw new ApplicationException("Unknown pixel format: " + format.PixelFormat); } if (disposePixbuf) { pixbuf.Dispose(); } return(data); }
private void GenerateScaledBuffer() { var xMin = 0.0; var xMax = 0.0; var yMin = 0.0; var yMax = 0.0; foreach (var point in Points) { if (point.Item1 < xMin) { xMin = point.Item1; } if (point.Item1 > xMax) { xMax = point.Item1; } if (point.Item1 < yMin) { yMin = point.Item2; } if (point.Item1 > yMax) { yMax = point.Item2; } } var width = xMax - xMin; var height = yMax - yMin; var xDiff = _pixBuf.Width - width; var yDiff = _pixBuf.Height - height; var scale = 1.0; if (xDiff > yDiff) { scale = height / _pixBuf.Height; } else { scale = width / _pixBuf.Width; } var scaledWidth = (int)(_pixBuf.Width * scale); var scaledHeight = (int)(_pixBuf.Height * scale); if (_scaledPixBuf != null) { _scaledPixBuf.Dispose(); } _scaledPixBuf = _pixBuf.ScaleSimple(scaledWidth, scaledHeight, Gdk.InterpType.Bilinear); }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated(allocation); if (savedPalette != null) { savedPalette.Dispose(); } int W = Allocation.Width, H = Allocation.Height; // Drawing color matrix to back pixbuf savedPalette = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, W - margin * 2, H - margin * 2); DrawPalette(savedPalette); }
public static Gdk.Pixbuf ToPixbuf(ArtworkFormat format, byte[] data) { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, format.Width, format.Height); Gdk.Pixbuf rotated = null; switch (format.PixelFormat) { case PixelFormat.Rgb565: UnpackRgb565(data, pixbuf, false); break; case PixelFormat.Rgb565BE: UnpackRgb565(data, pixbuf, true); break; case PixelFormat.IYUV: UnpackIYUV(data, pixbuf); break; default: throw new ApplicationException("Unknown pixel format: " + format.PixelFormat); } if (format.Rotation > 0) { rotated = Rotate(pixbuf, format.Rotation); pixbuf.Dispose(); pixbuf = rotated; } return(pixbuf); }
private void SetImage() { Gdk.Pixbuf pbuf = DockServices.Drawing.EmptyPixbuf; try { if (OwnedObject.ForcePixbuf != null) { pbuf = OwnedObject.ForcePixbuf.Copy(); if (pbuf.Width != IconSize || pbuf.Height != IconSize) { pbuf = pbuf.ARScale(IconSize, IconSize); } } else { pbuf = DockServices.Drawing.LoadIcon(OwnedObject.Icon, IconSize); } pbuf.AddHueShift(OwnedObject.HueShift); if (!OwnedObject.Enabled) { pbuf.MonochromePixbuf(); } } catch (Exception e) { Log <Tile> .Error("Error loading pixbuf for {0} tile: {1}", OwnedObject.Name, e.Message); Log <Tile> .Debug(e.StackTrace); pbuf = DockServices.Drawing.EmptyPixbuf; } finally { tileImage.Pixbuf = pbuf; pbuf.Dispose(); tileImage.Show(); } }
/// <summary> /// this function modifies a window shape /// </summary> /// <param name="bmp"> /// the bitmap that has the shape of the window. <see cref="System.Drawing.Bitmap"/> /// </param> /// <param name="window"> /// the window to apply the shape change <see cref="Gtk.Window"/> /// </param> /// <returns> /// true if it succeded, either return false <see cref="System.Boolean"/> /// </returns> public static bool ModifyWindowShape(System.Drawing.Bitmap bmp, Gtk.Window window) { bool ret = false; try { //save bitmap to stream System.IO.MemoryStream stream = new System.IO.MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); //verry important: put stream on position 0 stream.Position = 0; //get the pixmap mask Gdk.Pixbuf buf = new Gdk.Pixbuf(stream, bmp.Width, bmp.Height); Gdk.Pixmap map1, map2; buf.RenderPixmapAndMask(out map1, out map2, 255); //shape combine window window.ShapeCombineMask(map2, 0, 0); //dispose buf.Dispose(); map1.Dispose(); map2.Dispose(); bmp.Dispose(); //if evrything is ok return true; ret = true; } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } return(ret); }
public Gdk.Pixbuf Load(int max_width, int max_height) { Gdk.Pixbuf full = this.Load(); Gdk.Pixbuf scaled = PixbufUtils.ScaleToMaxSize(full, max_width, max_height); full.Dispose(); return(scaled); }
public override Gdk.Pixbuf Load(int width, int height) { Gdk.Pixbuf full = this.Load(); Gdk.Pixbuf scaled = PixbufUtils.ScaleToMaxSize(full, width, height); full.Dispose(); return(scaled); }
/// <summary> /// this function modifies a window shape /// </summary> /// <param name="bmp"> /// the bitmap that has the shape of the window. <see cref="System.Drawing.Bitmap"/> /// </param> /// <param name="window"> /// the window to apply the shape change <see cref="Gtk.Window"/> /// </param> /// <returns> /// true if it succeded, either return false <see cref="System.Boolean"/> /// </returns> public static bool ModifyWindowShape( System.Drawing.Bitmap bmp, Gtk.Window window ) { bool ret = false; try { //save bitmap to stream System.IO.MemoryStream stream = new System.IO.MemoryStream(); bmp.Save( stream, System.Drawing.Imaging.ImageFormat.Png ); //verry important: put stream on position 0 stream.Position = 0; //get the pixmap mask Gdk.Pixbuf buf = new Gdk.Pixbuf( stream, bmp.Width, bmp.Height ); Gdk.Pixmap map1, map2; buf.RenderPixmapAndMask( out map1, out map2, 255 ); //shape combine window window.ShapeCombineMask( map2, 0, 0 ); //dispose buf.Dispose(); map1.Dispose(); map2.Dispose(); bmp.Dispose(); //if evrything is ok return true; ret = true; } catch(Exception ex) { Console.WriteLine( ex.Message + "\r\n" + ex.StackTrace ); } return ret; }
private bool DelayedUpdateHistogram() { if (Photos.Length == 0) { return(false); } IPhoto photo = Photos[0]; Gdk.Pixbuf hint = histogram_hint; histogram_hint = null; int max = histogram_expander.Allocation.Width; try { if (hint == null) { using (var img = ImageFile.Create(photo.DefaultVersion.Uri)) { hint = img.Load(256, 256); } } histogram_image.Pixbuf = histogram.Generate(hint, max); hint.Dispose(); } catch (System.Exception e) { Hyena.Log.Debug(e.StackTrace); using (Gdk.Pixbuf empty = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 256, 256)) { empty.Fill(0x0); histogram_image.Pixbuf = histogram.Generate(empty, max); } } return(false); }
public void SetPixbufExtended(Gdk.Pixbuf value, bool ignore_undead) { lock (this) { if (IsDisposed) { if (ignore_undead) { return; } else { throw new System.Exception("I don't want to be undead"); } } Gdk.Pixbuf old = this.Pixbuf; cache.total_size -= this.Size; this.pixbuf = value; if (pixbuf != null) { this.width = pixbuf.Width; this.height = pixbuf.Height; } cache.total_size += this.Size; this.Reload = false; if (old != null) { old.Dispose(); } } }
private ImageInfo CreateBlur(ImageInfo source) { double scale = Math.Max(256 / (double)source.Bounds.Width, 256 / (double)source.Bounds.Height); Gdk.Rectangle small = new Gdk.Rectangle(0, 0, (int)Math.Ceiling(source.Bounds.Width * scale), (int)Math.Ceiling(source.Bounds.Height * scale)); ImageSurface image = new ImageSurface(Format.Argb32, small.Width, small.Height); Context ctx = new Context(image); ctx.Matrix = source.Fit(small); ctx.Operator = Operator.Source; Pattern p = new SurfacePattern(source.Surface); ctx.Source = p; ctx.Paint(); p.Destroy(); ((IDisposable)ctx).Dispose(); Gdk.Pixbuf normal = image.ToPixbuf(); Gdk.Pixbuf blur = PixbufUtils.Blur(normal, 3, null); ImageInfo overlay = new ImageInfo(blur); blur.Dispose(); normal.Dispose(); image.Destroy(); return(overlay); }
private void LoadPixbufs() { int width, height; Icon.SizeLookup(icon_size, out width, out height); IconTheme theme = IconTheme.GetForScreen(Screen); if (normal_pixbuf != null) { normal_pixbuf.Dispose(); normal_pixbuf = null; } if (active_pixbuf != null) { active_pixbuf.Dispose(); active_pixbuf = null; } for (int i = 0; i < icon_names.Length; i++) { try { normal_pixbuf = RenderIcon(icon_names[i], icon_size, null) ?? theme.LoadIcon(icon_names[i], width, 0); active_pixbuf = ColorShiftPixbuf(normal_pixbuf, 30); break; } catch { } } UpdateImage(); }
private void LoadPixbufs() { int width, height; Icon.SizeLookup(icon_size, out width, out height); if (normal_pixbuf != null) { normal_pixbuf.Dispose(); normal_pixbuf = null; } if (active_pixbuf != null) { active_pixbuf.Dispose(); active_pixbuf = null; } for (int i = 0; i < icon_names.Length; i++) { try { normal_pixbuf = ImageService.GetPixbuf(icon_names[i], icon_size); active_pixbuf = ColorShiftPixbuf(normal_pixbuf, 30); break; } catch { } } UpdateImage(); }
void HandleSelectionChanged(object sender, EventArgs e) { int x = image_view.Selection.X; int y = image_view.Selection.Y; int width = image_view.Selection.Width; int height = image_view.Selection.Height; if (image_view.Pixbuf != null) { if (image_view.Selection != Gdk.Rectangle.Zero) { using (var tmp = new Gdk.Pixbuf(image_view.Pixbuf, x, y, width, height)) { Gdk.Pixbuf transformed = FSpot.Utils.PixbufUtils.TransformOrientation(tmp, image_view.PixbufOrientation); PreviewPixbuf = PixbufUtils.TagIconFromPixbuf(transformed); transformed.Dispose(); } } else { Gdk.Pixbuf transformed = FSpot.Utils.PixbufUtils.TransformOrientation(image_view.Pixbuf, image_view.PixbufOrientation); PreviewPixbuf = PixbufUtils.TagIconFromPixbuf(transformed); transformed.Dispose(); } } }
private bool DelayedUpdateHistogram() { if (Photos.Length == 0) { return(false); } Photo photo = Photos[0]; Gdk.Pixbuf hint = histogram_hint; histogram_hint = null; try { if (hint == null) { using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) hint = img.Load(256, 256); } int max = histogram_expander.Allocation.Width; histogram_image.Pixbuf = histogram.Generate(hint, max); hint.Dispose(); } catch (System.Exception e) { Log.Debug(e.StackTrace); } return(false); }
public void SetPixbufExtended(Gdk.Pixbuf value, bool ignoreUndead) { lock (locker) { if (IsDisposed) { if (ignoreUndead) { return; } throw new Exception("I don't want to be undead"); } Gdk.Pixbuf old = Pixbuf; cache.total_size -= Size; pixbuf = value; if (pixbuf != null) { Width = pixbuf.Width; Height = pixbuf.Height; } cache.total_size += Size; Reload = false; if (old != null) { old.Dispose(); } } }
public void SaveLoad() { using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(null, "f-spot-32.png")) { Gdk.Pixbuf source = pixbuf; if (pixbuf.HasAlpha) { source = PixbufUtils.Flatten(pixbuf); } string path = ImageFile.TempPath("test.ppm"); PnmFile pnm = new PnmFile(path); using (Stream stream = File.OpenWrite(path)) { pnm.Save(source, stream); } pnm = new PnmFile(path); using (Gdk.Pixbuf saved = pnm.Load()) { Assert.IsNotNull(saved); Assert.AreEqual(saved.Width, source.Width); Assert.AreEqual(saved.Height, source.Height); } if (source != pixbuf) { source.Dispose(); } File.Delete(path); } }
void RenderSvgOnContext(Context cr, string file, int size) { Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon(file, size); Gdk.CairoHelper.SetSourcePixbuf(cr, pbuf, (pbuf.Width - size) / 2, (pbuf.Height - size) / 2); cr.Paint(); pbuf.Dispose(); }
protected override void LoadIcon(Gtk.Image image, int size) { base.LoadIcon(image, size); // Draw the F-Spot overlay if (size > 32 && Hit ["fspot:IsIndexed"] == "true") { Gdk.Pixbuf emblem = WidgetFu.LoadThemeIcon("f-spot", 24); Gdk.Pixbuf icon = image.Pixbuf.Copy(); if (icon == null || emblem == null) { return; } // FIXME: Ideally we'd composite into a fresh new pixbuf of // the correct size in this case, but really, who's going to // have images shorter or narrower than 16 pixels in f-spot?? if (icon.Height < emblem.Height || icon.Width < emblem.Width) { icon.Dispose(); emblem.Dispose(); return; } emblem.Composite(icon, 0, icon.Height - emblem.Height, emblem.Width, emblem.Height, 0, icon.Height - emblem.Height, 1, 1, Gdk.InterpType.Bilinear, 255); image.Pixbuf.Dispose(); image.Pixbuf = icon; } }
internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor) { Gdk.Pixbuf result = null; Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId); if (iconset != null) { // Find the size that better fits the requested size Gtk.IconSize gsize = Util.GetBestSizeFit(width); result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor); if (result == null || result.Width < width * scaleFactor) { var gsize2x = Util.GetBestSizeFit(width * scaleFactor, iconset.Sizes); if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize) { if (result != null) { result.Dispose(); } result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null); } } } if (result == null && Gtk.IconTheme.Default.HasIcon(stockId)) { result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0); } return(result); }
/// <summary> /// Does cleanup when the main widget is destroyed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _mainWidget_Destroyed(object sender, EventArgs e) { if (numberLockedCols > 0) { gridview.Vadjustment.ValueChanged -= Gridview_Vadjustment_Changed; gridview.Selection.Changed -= Gridview_CursorChanged; fixedcolview.Vadjustment.ValueChanged -= Fixedcolview_Vadjustment_Changed1; fixedcolview.Selection.Changed -= Fixedcolview_CursorChanged; } // It's good practice to disconnect the event handlers, as it makes memory leaks // less likely. However, we may not "own" the event handlers, so how do we // know what to disconnect? // We can do this via reflection. Here's how it currently can be done in Gtk#. // Windows.Forms would do it differently. // This may break if Gtk# changes the way they implement event handlers. ClearGridColumns(); gridmodel.Dispose(); if (imagePixbuf != null) { imagePixbuf.Dispose(); } if (image1 != null) { image1.Dispose(); } if (table != null) { table.Dispose(); } _mainWidget.Destroyed -= _mainWidget_Destroyed; _owner = null; }
private void HandleAreaPrepared(object sender, System.EventArgs args) { pixbuf = PixbufUtils.TransformOrientation(loader.Pixbuf, orientation, false); if (thumb != null && pixbuf != null) { thumb.Composite(pixbuf, 0, 0, pixbuf.Width, pixbuf.Height, 0.0, 0.0, pixbuf.Width / (double)thumb.Width, pixbuf.Height / (double)thumb.Height, Gdk.InterpType.Bilinear, 0xff); } if (thumb != null) { if (!ThumbnailGenerator.ThumbnailIsValid(thumb, uri)) { FSpot.ThumbnailGenerator.Default.Request(uri, 0, 256, 256); } } area_prepared = true; if (AreaUpdated != null) { AreaPrepared(this, new AreaPreparedArgs(false)); } if (thumb != null) { thumb.Dispose(); } thumb = null; }
private void UpdateIcons() { icon_names = job.IconNames; if (icon_pixbuf != null) { icon_pixbuf.Dispose(); icon_pixbuf = null; } if (icon_names == null || icon_names.Length == 0) { icon.Hide(); return; } icon_pixbuf = IconThemeUtils.LoadIcon(22, icon_names); if (icon_pixbuf != null) { icon.Pixbuf = icon_pixbuf; icon.Show(); return; } icon_pixbuf = new Gdk.Pixbuf(icon_names[0]); if (icon_pixbuf != null) { Gdk.Pixbuf scaled = icon_pixbuf.ScaleSimple(22, 22, Gdk.InterpType.Bilinear); icon_pixbuf.Dispose(); icon.Pixbuf = scaled; icon.Show(); } }
private void CreateThumbnail() { Gdk.PixbufAnimation animation = this.LoadAnimation(); Gdk.Pixbuf staticImage = animation.StaticImage; var dbConfig = BooruApp.BooruApplication.Database.Config; float thumbSize = dbConfig.GetInt("thumbs.size"); float scale = Math.Min(thumbSize / staticImage.Width, thumbSize / staticImage.Height); int w = (int)(staticImage.Width * scale); int h = (int)(staticImage.Height * scale); this.cachedThumbnail = staticImage.ScaleSimple(w, h, Gdk.InterpType.Hyper); if (staticImage.Width > 0 && staticImage.Height > 0) { if (this.Details.Size.IsZero) { BooruApp.BooruApplication.Database.SetImageSize(this.Details.MD5, new Point2D(staticImage.Width, staticImage.Height)); } } // only dispose if not from cached animation if (this.cachedAnimation != animation) { animation.Dispose(); staticImage.Dispose(); } }
public void InitObject(String name, System.Drawing.Color color, String labelText, int fontSize, String image, String overlay, int width, int height) { String stringImageFilename = _pathCache + name + ".png"; System.Drawing.Bitmap bitmap; if (_useCachedImages && File.Exists(stringImageFilename)) { //Load cached Thumbnail bitmap = new System.Drawing.Bitmap(stringImageFilename); } else { //createThumbnail bitmap = CreateThumbnail(name, color, labelText, fontSize, image, overlay, width, height); } //create pixBuf + gtkImage Gdk.Pixbuf pixBuf = Utils.ImageToPixbuf(bitmap); Image gtkImage = new Image(pixBuf); //free resources bitmap.Dispose(); pixBuf.Dispose(); widget = gtkImage; }
public void InitObject(String name, System.Drawing.Color color, String labelText, String font, System.Drawing.Color colorFont, String icon, System.Drawing.Size sizeIcon, int width, int height) { VBox vbox = new VBox(false, 0); vbox.BorderWidth = 2; System.Drawing.Image imageIcon; _label = new Label(labelText); ChangeFont(font, colorFont); if (icon != string.Empty && File.Exists(icon)) { try { imageIcon = System.Drawing.Image.FromFile(icon); imageIcon = Utils.ResizeAndCrop(imageIcon, sizeIcon); Gdk.Pixbuf pixBuf = Utils.ImageToPixbuf(imageIcon); Image gtkimageButton = new Image(pixBuf); vbox.PackStart(gtkimageButton); imageIcon.Dispose(); pixBuf.Dispose(); } catch (Exception ex) { _log.Error(string.Format("InitObject(): Error load icon from file [{0}]: {1}", icon, ex.Message), ex); } } vbox.PackStart(_label); _widget = vbox; }
public override void Dispose() { base.Dispose(); if (black_donut != null) { black_donut.Dispose(); } if (white_donut != null) { white_donut.Dispose(); } if (black_dot != null) { black_dot.Dispose(); } if (white_dot != null) { white_dot.Dispose(); } if (savedPalette != null) { savedPalette.Dispose(); } }
protected virtual void UpdateSample() { if (source != null) { source.Dispose(); } source = null; if (view.Pixbuf == null) { return; } int small = (int)(radius * view.Zoom); if (small != inner) { inner = small; QueueResize(); } source = new Gdk.Pixbuf(view.Pixbuf, region.X, region.Y, region.Width, region.Height); //FIXME sometimes that ctor returns results with a null //handle this case ourselves if (source.Handle == IntPtr.Zero) { source = null; } this.QueueDraw(); }
public static Gdk.Pixbuf GetPixbufFromNSImageRep(NSImageRep rep, int width, int height) { var rect = new System.Drawing.RectangleF(0, 0, width, height); var bitmap = rep as NSBitmapImageRep; if (bitmap == null) { using (var cgi = rep.AsCGImage(rect, null, null)) bitmap = new NSBitmapImageRep(cgi); } try { byte[] data; using (var tiff = bitmap.TiffRepresentation) { data = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy(tiff.Bytes, data, 0, data.Length); } int pw = bitmap.PixelsWide, ph = bitmap.PixelsHigh; var pixbuf = new Gdk.Pixbuf(data, pw, ph); // if one dimension matches, and the other is same or smaller, use as-is if ((pw == width && ph <= height) || (ph == height && pw <= width)) { return(pixbuf); } // otherwise scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = width; ph = height; } else if (pw > ph) { ph = (int)(width * ((float)ph / pw)); pw = width; } else { pw = (int)(height * ((float)pw / ph)); ph = height; } var scaled = pixbuf.ScaleSimple(pw, ph, Gdk.InterpType.Bilinear); pixbuf.Dispose(); return(scaled); } finally { if (bitmap != rep) { bitmap.Dispose(); } } }
protected override void OnDestroyed() { if (!hasInactiveImage && inactiveImage != null) { inactiveImage.Dispose(); } base.OnDestroyed(); }
public bool Convert (FilterRequest req) { string source = req.Current.LocalPath; System.Uri dest_uri = req.TempUri (System.IO.Path.GetExtension (source)); string dest = dest_uri.LocalPath; using (ImageFile img = ImageFile.Create (source)) { bool changed = false; if (img.Orientation != PixbufOrientation.TopLeft && img is JpegFile) { JpegFile jimg = img as JpegFile; if (img.Orientation == PixbufOrientation.RightTop) { JpegUtils.Transform (source, dest, JpegUtils.TransformType.Rotate90); changed = true; } else if (img.Orientation == PixbufOrientation.LeftBottom) { JpegUtils.Transform (source, dest, JpegUtils.TransformType.Rotate270); changed = true; } else if (img.Orientation == PixbufOrientation.BottomRight) { JpegUtils.Transform (source, dest, JpegUtils.TransformType.Rotate180); changed = true; } int width, height; jimg = ImageFile.Create (dest) as JpegFile; PixbufUtils.GetSize (dest, out width, out height); jimg.SetOrientation (PixbufOrientation.TopLeft); jimg.SetDimensions (width, height); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (dest, 160, 120, true); jimg.SetThumbnail (pixbuf); pixbuf.Dispose (); jimg.SaveMetaData (dest); jimg.Dispose (); } if (changed) req.Current = dest_uri; return changed; } }
protected override Gdk.Pixbuf OnGetPixbufForFile (string filename, Gtk.IconSize size) { NSImage icon = null; //FIXME: better handling of names of files that haven't been saved yet if (Path.IsPathRooted (filename)) { icon = NSWorkspace.SharedWorkspace.IconForFile (filename); } else { icon = NSWorkspace.SharedWorkspace.IconForFile ("/tmp/" + filename); } if (icon != null) { int w, h; if (!Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out w, out h)) w = h = 22; var rect = new System.Drawing.RectangleF (0, 0, w, h); var rep = icon.BestRepresentation (rect, null, null) as NSBitmapImageRep; if (rep != null) { var tiff = rep.TiffRepresentation; byte[] arr = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy (tiff.Bytes, arr, 0, arr.Length); int pw = rep.PixelsWide, ph = rep.PixelsHigh; var px = new Gdk.Pixbuf (arr, pw, ph); //if one dimension matches, and the other is same or smaller, use as-is if ((pw == w && ph <= h) || (ph == h && pw <= w)) return px; //else scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = w; ph = h; } else if (pw > ph) { ph = (int) (w * ((float) ph / pw)); pw = w; } else { pw = (int) (h * ((float) pw / ph)); ph = h; } var scaled = px.ScaleSimple (pw, ph, Gdk.InterpType.Bilinear); px.Dispose (); return scaled; } } return base.OnGetPixbufForFile (filename, size); }
protected override void OnDrawPage(Gtk.PrintContext context, int page_nr) { base.OnDrawPage (context, page_nr); Context cr = context.CairoContext; int ppx, ppy; switch (photos_per_page) { default: case 1: ppx = ppy =1; break; case 2: ppx = 1; ppy = 2; break; case 4: ppx = ppy = 2; break; case 9: ppx = ppy = 3; break; case 12: ppx = 3; ppy = 4; break; case 20: ppx = 4; ppy = 5; break; case 30: ppx = 5; ppy = 6; break; } //FIXME: if paper is landscape, swap ppx with ppy double w = context.Width / ppx; double h = context.Height / ppy; // compute picture size using 4800DPI double mx=(w / 25.4) * 4800, my=(h / 25.4) * 4800; for (int x = 0; x <= ppx; x++) { for (int y = 0; y <= ppy; y++) { int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x; if (crop_marks) DrawCropMarks (cr, x*w, y*h, w*.1); if (x == ppx || y == ppy || p_index >= selected_photos.Length) continue; using (var img = ImageFile.Create (selected_photos[p_index].DefaultVersion.Uri)) { Gdk.Pixbuf pixbuf; try { pixbuf = img.Load ((int) mx, (int) my); Cms.Profile printer_profile; if (FSpot.ColorManagement.Profiles.TryGetValue (Preferences.Get<string> (Preferences.COLOR_MANAGEMENT_OUTPUT_PROFILE), out printer_profile)) FSpot.ColorManagement.ApplyProfile (pixbuf, img.GetProfile (), printer_profile); } catch (Exception e) { Log.Exception ("Unable to load image " + selected_photos[p_index].DefaultVersion.Uri + "\n", e); // If the image is not found load error pixbuf pixbuf = new Gdk.Pixbuf (PixbufUtils.ErrorPixbuf, 0, 0, PixbufUtils.ErrorPixbuf.Width, PixbufUtils.ErrorPixbuf.Height); } //Gdk.Pixbuf pixbuf = img.Load (100, 100); bool rotated = false; if (Math.Sign ((double)pixbuf.Width/pixbuf.Height - 1.0) != Math.Sign (w/h - 1.0)) { Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple (Gdk.PixbufRotation.Counterclockwise); pixbuf.Dispose (); pixbuf = d_pixbuf; rotated = true; } DrawImage (cr, pixbuf, x * w, y * h, w, h); string tag_string = ""; foreach (Tag t in selected_photos[p_index].Tags) tag_string = String.Concat (tag_string, t.Name); string label = String.Format (print_label_format, comment, selected_photos[p_index].Name, selected_photos[p_index].Time.ToLocalTime ().ToShortDateString (), selected_photos[p_index].Time.ToLocalTime ().ToShortTimeString (), tag_string, selected_photos[p_index].Description); DrawComment (context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, label, rotated); pixbuf.Dispose (); } } } }
private void DrawImage(PageImage pi, Cairo.Context g, Cairo.Rectangle r) { // Stream strm = null; // System.Drawing.Image im = null; Gdk.Pixbuf im = null; try { // strm = new MemoryStream (pi.ImageData); // im = System.Drawing.Image.FromStream (strm); im = new Gdk.Pixbuf(pi.ImageData); DrawImageSized(pi, im, g, r); } finally { // if (strm != null) // strm.Close(); if (im != null) im.Dispose(); } }
private void UpdateIcons() { icon_names = job.IconNames; if (icon_pixbuf != null) { icon_pixbuf.Dispose (); icon_pixbuf = null; } if (icon_names == null || icon_names.Length == 0) { icon.Hide (); return; } icon_pixbuf = IconThemeUtils.LoadIcon (22, icon_names); if (icon_pixbuf != null) { icon.Pixbuf = icon_pixbuf; icon.Show (); return; } try { icon_pixbuf = new Gdk.Pixbuf (icon_names[0]); } catch (GLib.GException) {} if (icon_pixbuf != null) { Gdk.Pixbuf scaled = icon_pixbuf.ScaleSimple (22, 22, Gdk.InterpType.Bilinear); icon_pixbuf.Dispose (); icon.Pixbuf = scaled; icon.Show (); } }
public bool ForceLoadAttr() { // Don't waste our resources if it has been removed from the list if (!removed) { if (!IO.File.Exists(filename)) { // mark it as removed so it dosen't get listed as an option, ever removed = true; // set filename to null, so it dosen't get saved on quit filename = null; Console.WriteLine(Catalog.GetString("Cannot find file: {0}"), filename); // No sence doing anything else return false; } if (mtime == CurrentMtime) { goto done; } else // save mtime mtime = CurrentMtime; try { // Not loaded Pixbuf t = new Gdk.Pixbuf(filename); w = t.Width; h = t.Height; t.Dispose(); // try to catch that random no data exception that will happen dude to inotify catching // wallpapers that are created but are not filled with data (yet) } catch (GLib.GException) { DrapesApp.WpList.RemoveFromList(filename); } // Try to generate a thumbnail CreateThumnail(); } else return true; done: // We're done init = true; return true; }
/// <summary> /// Charge une image de test. /// </summary> private static GreyPixbuf LoadImage(string ImagePath) { var pixbuf = new Gdk.Pixbuf(ImagePath); var scaledPixbuf = pixbuf.ScaleSimple(Config.WindowWidth, Config.WindowHeight, Gdk.InterpType.Hyper); pixbuf.Dispose(); return new GreyPixbuf(scaledPixbuf); }
protected virtual void ProcessRequest (CacheEntry entry) { Gdk.Pixbuf loaded = null; try { loaded = new Gdk.Pixbuf (entry.Path); this.Update (entry, loaded); } catch (GLib.GException){ if (loaded != null) loaded.Dispose (); return; } }
public static void GenerateMipMap (IPhoto photo) { var mipmap_uri = MipMapUri (photo); Log.DebugFormat ("Generating mipmap for {0} - {1}", photo.Uri.ToString (), mipmap_uri.AbsoluteUri); var file = GLib.FileFactory.NewForUri (photo.Uri); var pixbuf = new Gdk.Pixbuf (new GLib.GioStream (file.Read (null))); var imagefile = TagLib.File.Create (new GIOTagLibFileAbstraction () { Uri = photo.Uri }) as TagLib.Image.File; var tag = imagefile.ImageTag; // Correct orientation pixbuf = pixbuf.TransformOrientation (tag.Orientation); // Determine mode var mode = pixbuf.Width > pixbuf.Height ? ScaleMode.Width : ScaleMode.Height; var longest = mode == ScaleMode.Width ? pixbuf.Width : pixbuf.Height; double scale_factor = Math.Max ((double) longest / 1600, 1.0); MipMapFile map = new MipMapFile (); List<Gdk.Pixbuf> pixbufs = new List<Gdk.Pixbuf>(7); // Six or seven on average if (scale_factor > 1.0) { using (var tmp = pixbuf) pixbuf = pixbuf.ScaleSimple ((int) Math.Round (pixbuf.Width / scale_factor), (int) Math.Round (pixbuf.Height / scale_factor), Gdk.InterpType.Bilinear); } int max; do { max = Math.Max (pixbuf.Width, pixbuf.Height); pixbufs.Add (pixbuf); pixbuf = pixbuf.ScaleSimple (pixbuf.Width / 2, pixbuf.Height / 2, Gdk.InterpType.Bilinear); } while (max > 64); pixbuf.Dispose (); // As the mipmap items are built from largest -> smallest, we need to add them in reverse. pixbufs.Reverse (); foreach (var buf in pixbufs) { map.Add (buf); } map.WriteToUri (mipmap_uri); }
protected override void OnDrawPage (Gtk.PrintContext context, int page_nr) { base.OnDrawPage (context, page_nr); Context cr = context.CairoContext; int ppx, ppy; switch (photos_per_page) { default: case 1: ppx = ppy =1; break; case 2: ppx = 1; ppy = 2; break; case 4: ppx = ppy = 2; break; case 9: ppx = ppy = 3; break; } //FIXME: if paper is landscape, swap ppx with ppy double w = context.Width / ppx; double h = context.Height / ppy; for (int x = 0; x <= ppx; x++) { for (int y = 0; y <= ppy; y++) { int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x; if (crop_marks) DrawCropMarks (cr, x*w, y*h, w*.1); if (x == ppx || y == ppy || p_index >= selected_photos.Length) continue; using (ImageFile img = new ImageFile (selected_photos[p_index].DefaultVersionUri)) { Gdk.Pixbuf pixbuf; try { pixbuf = img.Load (); FSpot.ColorManagement.ApplyPrinterProfile (pixbuf, img.GetProfile ()); } catch (Exception e) { Log.Exception ("Unable to load image " + selected_photos[p_index].DefaultVersionUri + "\n", e); // If the image is not found load error pixbuf pixbuf = new Gdk.Pixbuf (PixbufUtils.ErrorPixbuf, 0, 0, PixbufUtils.ErrorPixbuf.Width, PixbufUtils.ErrorPixbuf.Height); } //Gdk.Pixbuf pixbuf = img.Load (100, 100); bool rotated = false; if (Math.Sign ((double)pixbuf.Width/pixbuf.Height - 1.0) != Math.Sign (w/h - 1.0)) { Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple (Gdk.PixbufRotation.Counterclockwise); pixbuf.Dispose (); pixbuf = d_pixbuf; rotated = true; } DrawImage (cr, pixbuf, x * w, y * h, w, h); DrawComment (context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, comment, rotated); pixbuf.Dispose (); } } } }
protected override Gdk.Pixbuf OnGetPixbufForFile (string filename, Gtk.IconSize size) { //this only works on MacOS 10.6.0 and greater if (systemVersion < 0x1060) return base.OnGetPixbufForFile (filename, size); NSImage icon = null; if (Path.IsPathRooted (filename) && File.Exists (filename)) { icon = NSWorkspace.SharedWorkspace.IconForFile (filename); } else { string extension = Path.GetExtension (filename); if (!string.IsNullOrEmpty (extension)) icon = NSWorkspace.SharedWorkspace.IconForFileType (extension); } if (icon == null) { return base.OnGetPixbufForFile (filename, size); } int w, h; if (!Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out w, out h)) { w = h = 22; } var rect = new System.Drawing.RectangleF (0, 0, w, h); var arep = icon.BestRepresentation (rect, null, null); if (arep == null) { return base.OnGetPixbufForFile (filename, size); } var rep = arep as NSBitmapImageRep; if (rep == null) { using (var cgi = arep.AsCGImage (rect, null, null)) rep = new NSBitmapImageRep (cgi); arep.Dispose (); } try { byte[] arr; using (var tiff = rep.TiffRepresentation) { arr = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy (tiff.Bytes, arr, 0, arr.Length); } int pw = rep.PixelsWide, ph = rep.PixelsHigh; var px = new Gdk.Pixbuf (arr, pw, ph); //if one dimension matches, and the other is same or smaller, use as-is if ((pw == w && ph <= h) || (ph == h && pw <= w)) return px; //else scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = w; ph = h; } else if (pw > ph) { ph = (int) (w * ((float) ph / pw)); pw = w; } else { pw = (int) (h * ((float) pw / ph)); ph = h; } var scaled = px.ScaleSimple (pw, ph, Gdk.InterpType.Bilinear); px.Dispose (); return scaled; } finally { if (rep != null) rep.Dispose (); } }
public void Save () { if (!Changed) { this.Dialog.Destroy (); return; } if (!view.Item.IsValid) return; Console.WriteLine ("Saving...."); Photo photo = (Photo)view.Item.Current; try { bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId; Gdk.Pixbuf orig = view.CompletePixbuf (); Gdk.Pixbuf final = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8, orig.Width, orig.Height); Cms.Profile abs = AdjustmentProfile (); // FIXME this shouldn't use the screen as the destination profile. Cms.Profile destination = Cms.Profile.GetScreenProfile (view.Screen); if (destination == null) destination = Cms.Profile.CreateStandardRgb (); Cms.Profile [] list = new Cms.Profile [] { image_profile, abs, destination }; Cms.Transform transform = new Cms.Transform (list, PixbufUtils.PixbufCmsFormat (orig), PixbufUtils.PixbufCmsFormat (final), Cms.Intent.Perceptual, 0x0000); PixbufUtils.ColorAdjust (orig, final, transform); photo.SaveVersion (final, create_version); ((PhotoQuery)view.Query).Commit (view.Item.Index); final.Dispose (); } catch (System.Exception e) { string msg = Catalog.GetString ("Error saving adjusted photo"); string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to save photo {1}"), e.Message, photo.Name); HigMessageDialog md = new HigMessageDialog ((Gtk.Window)Dialog.Toplevel, DialogFlags.DestroyWithParent, Gtk.MessageType.Error, ButtonsType.Ok, msg, desc); md.Run (); md.Destroy (); } this.Dialog.Sensitive = false; this.Dialog.Destroy (); }
protected virtual void OnLogodrawingareaExposeEvent(object o, Gtk.ExposeEventArgs args) { Gdk.Window win; Gdk.Pixbuf logo, frame; int width, height, allocWidth, allocHeight, logoX, logoY; float ratio; if(logopix == null) return; logo = logopix.Value; win = logodrawingarea.GdkWindow; width = logo.Width; height = logo.Height; allocWidth = logodrawingarea.Allocation.Width; allocHeight = logodrawingarea.Allocation.Height; /* Checking if allocated space is smaller than our logo */ if((float) allocWidth / width > (float) allocHeight / height) { ratio = (float) allocHeight / height; } else { ratio = (float) allocWidth / width; } width = (int)(width * ratio); height = (int)(height * ratio); logoX = (allocWidth / 2) - (width / 2); logoY = (allocHeight / 2) - (height / 2); /* Drawing our frame */ frame = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, allocWidth, allocHeight); logo.Composite(frame, 0, 0, allocWidth, allocHeight, logoX, logoY, ratio, ratio, Gdk.InterpType.Bilinear, 255); win.DrawPixbuf(this.Style.BlackGC, frame, 0, 0, 0, 0, allocWidth, allocHeight, Gdk.RgbDither.Normal, 0, 0); frame.Dispose(); return; }
private void RenderBaseImagePreview() { var pixBuf = new Gdk.Pixbuf (_model.ImageUri.OriginalString); var scale = (float)_previewImage.Parent.Allocation.Width / (float)pixBuf.Width; var scaledWidht = (int)(pixBuf.Width * scale); var scaledHeight = (int)(pixBuf.Height * scale); var scaledPixBuf = pixBuf.ScaleSimple (scaledWidht, scaledHeight, Gdk.InterpType.Bilinear); _previewImage.Pixbuf = scaledPixBuf; pixBuf.Dispose (); scaledPixBuf.Dispose (); }
public bool IsImage(string fileName) { try { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(fileName); pixbuf.Dispose(); return(true); } catch (GLib.GException) { return(false); } }
public void ReadDone (object sender, System.EventArgs args) { if (result == null) return; int len = 0; try { len = stream.EndRead (result); //System.Console.WriteLine ("read {0} bytes", len); loader.Write (buffer, (ulong)len); } catch (System.ObjectDisposedException od) { System.Console.WriteLine ("error in endread {0}", od); //delay.Start (); len = -1; } catch (GLib.GException e) { System.Console.WriteLine (e.ToString ()); pixbuf = null; len = -1; } result = null; if (len <= 0) { if (loader.Pixbuf == null) { if (pixbuf != null) pixbuf.Dispose (); pixbuf = null; } UpdateListeners (); done_reading = true; Close (); return; } }
void Finish () { // try loading the logo, if this fails, then we use the backup. try { Gdk.Pixbuf pbuf = new Gdk.Pixbuf (LogoFile); pbuf.Dispose (); // if we get to this point, the logofile will load just fine Icon = LogoFile; } catch { // delete the bad logofile, if it exists if (System.IO.File.Exists (LogoFile)) System.IO.File.Delete (LogoFile); ForcePixbuf = DockServices.Drawing.LoadIcon ("nprlogo.gif@" + GetType ().Assembly.FullName, 128, -1); } IsLoaded = true; OnFinishedLoading (); }
protected void UpdatePreview() { thumb_image.Clear(); FileIsGood = false; int size = 200, margins = 30; if (System.IO.File.Exists(mFilename)) // Selected item is a file { origsize_label.Markup = ""; GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate { Gdk.Pixmap pm = null; Gdk.GC gc = null; Gdk.Pixbuf pb = null; try { pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1); gc = new Gdk.GC(thumb_image.GdkWindow); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename); string idtext = ""; try { idtext += "Shot has been taken\n" + " on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n"; idtext += " with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n"; idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n"; if (rdl.Shutter > 1) idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n"; else idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n"; idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" + "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n"; if (rdl.Artist != "") idtext += "Artist: <b>" + rdl.Artist + "</b>\n"; if (rdl.Description != "") idtext += "Description: <b>" + rdl.Description + "</b>\n"; Console.WriteLine(rdl.Flip); // Creating the thumbnail pixbuf pb = new Gdk.Pixbuf(rdl.ThumbnailData); } catch (Exception ex) { Console.WriteLine("Can't load the thumbnail: " + ex.Message); idtext += "\n<i>Can't load the thumbnail.</i>"; } identification_label.Markup = idtext; if (pb != null) { // Scaling the thumbnail Gdk.Pixbuf pbold = pb; int imgw = pb.Width, imgh = pb.Height; if (pb.Width > pb.Height) pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); else pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); pbold.Dispose(); // Rotating the thumbnail if (rdl.Flip != RawDescriptionLoader.FlipValues.None) { pbold = pb; if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown) pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown); else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Clockwise); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise); } pbold.Dispose(); } origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>"; pm.DrawPixbuf(gc, pb, 0, 0, (size + margins) / 2 - pb.Width / 2, (size + margins) / 2 - pb.Height / 2, pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0); thumb_image.SetFromPixmap(pm, null); pb.Dispose(); } FileIsGood = true; } catch (Exception #if DEBUG ex #endif ) { #if DEBUG Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message); #endif identification_label.Wrap = true; identification_label.Markup = "<i>Cannot decode the selected file. "+ "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>"; FileIsGood = false; } finally { if (gc != null) gc.Dispose(); if (pm != null) pm.Dispose(); } return false; })); } }
public Gdk.Pixbuf GetEmbeddedThumbnail () { if (this.ExifData.Data.Length > 0) { MemoryStream mem = new MemoryStream (this.ExifData.Data); Gdk.Pixbuf thumb = new Gdk.Pixbuf (mem); Gdk.Pixbuf rotated = PixbufUtils.TransformOrientation (thumb, this.Orientation); if (rotated != thumb) thumb.Dispose (); mem.Close (); return rotated; } return null; }
public static Gdk.Pixbuf GetPixbufFromNSImageRep (NSImageRep rep, int width, int height) { var rect = new RectangleF (0, 0, width, height); var bitmap = rep as NSBitmapImageRep; if (bitmap == null) { using (var cgi = rep.AsCGImage (ref rect, null, null)) bitmap = new NSBitmapImageRep (cgi); } try { byte[] data; using (var tiff = bitmap.TiffRepresentation) { data = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy (tiff.Bytes, data, 0, data.Length); } int pw = bitmap.PixelsWide, ph = bitmap.PixelsHigh; var pixbuf = new Gdk.Pixbuf (data, pw, ph); // if one dimension matches, and the other is same or smaller, use as-is if ((pw == width && ph <= height) || (ph == height && pw <= width)) return pixbuf; // otherwise scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = width; ph = height; } else if (pw > ph) { ph = (int) (width * ((float) ph / pw)); pw = width; } else { pw = (int) (height * ((float) pw / ph)); ph = height; } var scaled = pixbuf.ScaleSimple (pw, ph, Gdk.InterpType.Bilinear); pixbuf.Dispose (); return scaled; } finally { if (bitmap != rep) bitmap.Dispose (); } }
public static Gdk.Pixbuf ToPixbuf(ArtworkFormat format, byte[] data) { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8, format.Width, format.Height); Gdk.Pixbuf rotated = null; switch (format.PixelFormat) { case PixelFormat.Rgb565: UnpackRgb565 (data, pixbuf, false); break; case PixelFormat.Rgb565BE: UnpackRgb565 (data, pixbuf, true); break; case PixelFormat.IYUV: UnpackIYUV (data, pixbuf); break; default: throw new ApplicationException ("Unknown pixel format: " + format.PixelFormat); } if (format.Rotation > 0) { rotated = Rotate (pixbuf, format.Rotation); pixbuf.Dispose (); pixbuf = rotated; } return pixbuf; }