IconFromPixbuf() public static method

public static IconFromPixbuf ( Pixbuf source, int size ) : Pixbuf
source Pixbuf
size int
return Pixbuf
コード例 #1
0
        protected virtual Pixbuf GetPixbuf(int i, bool highlighted)
        {
            string thumb_path;
            Pixbuf current;

            try {
                thumb_path = FSpot.ThumbnailGenerator.ThumbnailPath((selection.Collection [i]).DefaultVersionUri);
                current    = PixbufUtils.ShallowCopy(thumb_cache.Get(thumb_path));
            } catch (IndexOutOfRangeException) {
                thumb_path = null;
                current    = null;
            }

            if (current == null)
            {
                try {
                    ThumbnailGenerator.Default.Request((selection.Collection [i]).DefaultVersionUri, 0, 256, 256);

                    if (SquaredThumbs)
                    {
                        current = new Pixbuf(thumb_path);
                        current = PixbufUtils.IconFromPixbuf(current, ThumbSize);
                    }
                    else
                    {
                        current = new Pixbuf(thumb_path, -1, ThumbSize);
                    }
                    thumb_cache.Add(thumb_path, current);
                } catch {
                    try {
                        current = FSpot.Global.IconTheme.LoadIcon("gtk-missing-image", ThumbSize, (Gtk.IconLookupFlags) 0);
                    } catch {
                        current = null;
                    }
                    thumb_cache.Add(thumb_path, null);
                }
            }

            //FIXME
            if (FSpot.ColorManagement.IsEnabled)
            {
                current = current.Copy();
                FSpot.ColorManagement.ApplyScreenProfile(current);
            }

            if (!highlighted)
            {
                return(current);
            }

            Pixbuf highlight = new Pixbuf(Gdk.Colorspace.Rgb, true, 8, current.Width, current.Height);

            Gdk.Color color = Style.Background(StateType.Selected);
            uint      ucol  = (uint)((uint)color.Red / 256 << 24) + ((uint)color.Green / 256 << 16) + ((uint)color.Blue / 256 << 8) + 255;

            highlight.Fill(ucol);
            current.CopyArea(1, 1, current.Width - 2, current.Height - 2, highlight, 1, 1);
            return(highlight);
        }
コード例 #2
0
        protected virtual Pixbuf GetPixbuf(int i, bool highlighted)
        {
            Pixbuf  current = null;
            SafeUri uri     = (selection.Collection [i]).DefaultVersion.Uri;

            try {
                var pixbuf = thumb_cache.Get(uri);
                if (pixbuf != null)
                {
                    current = pixbuf.ShallowCopy();
                }
            } catch (IndexOutOfRangeException) {
                current = null;
            }

            if (current == null)
            {
                var pixbuf = XdgThumbnailSpec.LoadThumbnail(uri, ThumbnailSize.Large, null);
                if (pixbuf == null)
                {
                    ThumbnailLoader.Default.Request(uri, ThumbnailSize.Large, 0);
                    current = FSpot.Core.Global.IconTheme.LoadIcon("gtk-missing-image", ThumbSize, (IconLookupFlags)0);
                }
                else
                {
                    if (SquaredThumbs)
                    {
                        current = PixbufUtils.IconFromPixbuf(pixbuf, ThumbSize);
                    }
                    else
                    {
                        current = pixbuf.ScaleSimple(ThumbSize, ThumbSize, InterpType.Nearest);
                    }
                    pixbuf.Dispose();
                    thumb_cache.Add(uri, current);
                }
            }

            //FIXME: we might end up leaking a pixbuf here
            Cms.Profile screen_profile;
            if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
            {
                Pixbuf t = current.Copy();
                current = t;
                ColorManagement.ApplyProfile(current, screen_profile);
            }

            // Add a four pixel white border around the thumbnail
            // for some reason we cannot use "using" here, it looks like the pixbuf copy is not done properly
            Pixbuf whiteBorder = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height);

            whiteBorder.Fill(0);
            current.CopyArea(1, 1, current.Width - 8, current.Height - 8, whiteBorder, 4, 4);
            current = whiteBorder;

            if (!highlighted)
            {
                return(current);
            }

            Pixbuf highlight = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height);

            highlight.Fill(ColorToInt(Style.Light(StateType.Selected)));

            // Add a two pixel highlight around the thumbnail
            current.CopyArea(2, 2, current.Width - 4, current.Height - 4, highlight, 2, 2);

            return(highlight);
        }