Пример #1
0
		/// <summary>
		/// Crea una imagen mas pequeña a partir de otra.
		/// </summary>
		/// <param name="image">
		/// La imagen a la que se le quiere hacer una previsualización.
		/// </param>
		/// <param name="size">
		/// El tamaño de la previsualización.
		/// </param>
		public static Gdk.Pixbuf MakeThumbnail(Gdk.Pixbuf image, int size)
		{
			float scale;
			
			// La escalamos para que no se distorsione.
			if(image.Width > image.Height)
			{
				scale = (float)(size)/image.Width;
			}
			else
			{
				scale = (float)(size)/image.Height;
			}
			
			int newWidth = (int)(scale*image.Width);
			int newHeight = (int)(scale*image.Height);
			
			Pixbuf res = 
				new Pixbuf(image.Colorspace, image.HasAlpha, image.BitsPerSample, size, size);
			
			res.Fill(0xFFFFFFFF);
				
			image.Scale(res,
			            0,0,
			            size, size,
			            (size -newWidth)/2,(size-newHeight)/2,
			            scale, scale, 
			            Gdk.InterpType.Bilinear );
			
				
			return res;
			
		}
Пример #2
0
        private static Gdk.Pixbuf Scale(Gdk.Pixbuf pixbuf, int width, int height, out int widthPadding,
                                         out int heightPadding)
        {
            if (pixbuf.Width == width && pixbuf.Height == height) {
                widthPadding = 0;
                heightPadding = 0;
                return pixbuf;
            }

            double scale = Math.Min  (width / (double) pixbuf.Width, height / (double) pixbuf.Height);

            int scaleWidth = (int) (scale * pixbuf.Width);
            int scaleHeight = (int) (scale * pixbuf.Height);

            Gdk.Pixbuf scaled = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8, width, height);
            scaled.Fill (0);

            widthPadding = width - scaleWidth;
            heightPadding = height - scaleHeight;

            pixbuf.Scale (scaled, widthPadding / 2, heightPadding / 2, scaleWidth, scaleHeight,
                          widthPadding / 2, heightPadding / 2, scale, scale, Gdk.InterpType.Bilinear);

            return scaled;
        }