Enviado por Llyn en .NET, Windows
Usar una imagen como portada de carpeta en Windows

Un tema corto, en Windows existen varias formas de tener una imagen como la portada de una carpeta, entre ellos están el crear un icono y añadirlo a desktop.ini, usar una opción (algo limitante) en versiones viejas del explorador. Existe una tercera el cual es tener un archivo Folder.jpg y AlbumArtSmall.jpg las cuales son usadas automáticamente por el explorador (y WMP, WMC, etc.) como portada de la carpeta.
El siguiente código (en C# para variar) emplea la tercera opción, se encarga de leer una imagen dada en la línea de comando del programa, crear una vista previa (con un borde añadido) y guardarlo como los archivos respectivos.
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace Utilities.SetFileAsFolderPicture
{
class FolderImage
{
string folder_path;
int border_width;
Color border_color;
public FolderImage(string path)
{
folder_path = path;
border_width = 0;
}
public void SetBorder(int width, Color color)
{
border_width = width;
border_color = color;
}
public void SetImage(Image image)
{
string albumart_path = Path.Combine(folder_path, "Folder.jpg");
string smallart_path = Path.Combine(folder_path, "AlbumArtSmall.jpg");
Size albumart_size = GetSize(image.Size, 200);
Size smallart_size = GetSize(image.Size, 75);
Save(image, albumart_size, albumart_path);
Save(image, smallart_size, smallart_path);
}
private Size GetSize(Size image, int size)
{
int width = image.Width, height = image.Height;
if (width > height)
{
return new Size(width * (size - border_width) / height + border_width, size);
}
else
{
return new Size(size, height * (size - border_width) / width + border_width);
}
}
private void Save(Image image, Size size, string path)
{
int width = size.Width, height = size.Height;
Bitmap output = new Bitmap(width, height);
Graphics graphics = Graphics.FromImage(output);
graphics.DrawImage(image, border_width, border_width, width - border_width * 2, height - border_width * 2);
graphics.DrawRectangle(new Pen(border_color, border_width), 0, 0, width, height);
output.Save(path, ImageFormat.Jpeg);
File.SetAttributes(path, FileAttributes.Hidden | FileAttributes.System);
}
}
}
A continuación, los archivos: FolderImage.cs y Program.cs
Posts Relacionados
- ¿Cómo jugar Prince of Persia en Windows 7 64 Bits? Hola! Bastante tiempo, eh? No, no me había olvidado de...
- Mostrar imagen desde una url en c# Buenas. En algún momento hemos necesitado que dada una url...
- Portapapeles en Windows Unos 135 días desde mi último post, pero quien los...
- Barra de menu con CSS e imagen de fondo Pués este metodo te permite tener una barra de menu...
- ¿Cómo iterar en sentido contrario? Respuesta: reverse_iterator Lo puedes conseguir en la librería STL, bajo...
- React OS el Windows gratuito Es sistema operativo basado en el diseño de Windows XP/2003....
- Botones CSS Misma Imagen efecto de hover y active // Antes de que FeCr sugiera que tome un descanso,...



Muy buen post man!
Este no sabia ese uso de la funcion system.drawing! lo usare en 7 cuando tenga oportunidad
pd: para enero se vienen cosas buenas, :D pero tendremos que esperar
Usando