void HandlePixbufLoaded(PixbufCache Cache, PixbufCache.CacheEntry entry) { Pixbuf result = entry.ShallowCopyPixbuf(); int order = (int)entry.Data; if (result == null) { return; } // We have to do the scaling here rather than on load because we need to preserve the // Pixbuf option iformation to verify the thumbnail validity later int width, height; PixbufUtils.Fit(result, ThumbnailWidth, ThumbnailHeight, false, out width, out height); if (result.Width > width && result.Height > height) { // Log.Debug ("scaling"); Pixbuf temp = result.ScaleSimple(width, height, InterpType.Nearest); result.Dispose(); result = temp; } else if (result.Width < ThumbnailWidth && result.Height < ThumbnailHeight) { // FIXME this is a workaround to handle images whose actual size is smaller than // the thumbnail size, it needs to be fixed at a different level. Pixbuf temp = new Pixbuf(Colorspace.Rgb, true, 8, ThumbnailWidth, ThumbnailHeight); temp.Fill(0x00000000); result.CopyArea(0, 0, result.Width, result.Height, temp, (temp.Width - result.Width) / 2, temp.Height - result.Height); result.Dispose(); result = temp; } Cache.Update(entry, result); InvalidateCell(order); }
protected CollectionGridView(IBrowsableCollection collection) { Collection = collection; Collection.Changed += (c) => { QueueResize(); }; Collection.ItemsChanged += (c, args) => { foreach (int item in args.Items) { if (args.Changes.DataChanged) { UpdateThumbnail(item); } InvalidateCell(item); } }; Name = "ImageContainer"; Cache = new PixbufCache(); Cache.OnPixbufLoaded += HandlePixbufLoaded; }