05 agosto 2006

Thumbnails con Mono - C# y Gtk

Despues de un tiempo de no poner codigo, aqui dejo lo que es el avance del organizador de fotos que estoy haciendo, donde incluire el almacenamiento en una base de datos (MySql), por el momento este codigo genera thumbnails y los muestra en un Treeview, todo esto esta programado en c# y Gtk.

Este codigo lo puedes utilizar y claro no olviden mencionar a gsur como su autor

//mcs -pkg:gtk-sharp dbimagen.cs
//mono dbimagen.exe

using System;
using Gtk;
using System.IO;

public class dbimagen
{
public static void Main()
{
Gtk.Application.Init();
new dbimagen();
Gtk.Application.Run();
}

static Gtk.TreeView tree;
static Gtk.Entry EntradaFolder;
static Gtk.Entry ancho;
static Gtk.Entry alto;
static FileSelection filew;
static Gtk.Entry EntradaThumb;
static Gtk.ListStore ImagenLista;

public dbimagen()
{
//Creacion de ventana
Gtk.Window window = new Gtk.Window("Generador de Thumbnails ver. 0.1");
window.SetSizeRequest(600, 400);
window.DeleteEvent+=new DeleteEventHandler(Window_Delete);

EntradaFolder = new Gtk.Entry();

Gtk.Label lblFolder = new Gtk.Label("Folder: ");

Gtk.HBox BoxSup = new Gtk.HBox();
Gtk.Button bexaminar = new Gtk.Button(Stock.Open);
bexaminar.Clicked += OnButtonClicked;

Gtk.Button bcargar = new Gtk.Button(Stock.Ok);
bcargar.Clicked += OnBCargarClicked;

Gtk.Label lblancho = new Gtk.Label("Ancho: ");
Gtk.Label lblalto = new Gtk.Label("Alto: ");
ancho = new Gtk.Entry("75");
alto = new Gtk.Entry("50");

BoxSup.PackStart(lblFolder, false, false, 5);
BoxSup.PackStart(EntradaFolder, false, false, 5);
BoxSup.PackStart(bexaminar, false, false, 5);
BoxSup.PackStart(bcargar, false, false, 5);
BoxSup.PackStart(lblancho, false, false, 5);
BoxSup.PackStart(ancho, true, true, 5);
BoxSup.PackStart(lblalto, false, false, 5);
BoxSup.PackStart(alto, true, true, 5);

//Creacion del Treeview donde se mostrara informacion de la imagen
tree = new Gtk.TreeView();

Gtk.VBox box = new Gtk.VBox();

box.PackStart(BoxSup, false, false, 5);
ScrolledWindow scrolledWindow = new ScrolledWindow ();
scrolledWindow.ShadowType = ShadowType.EtchedIn;
scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic);
scrolledWindow.Add(tree);
box.PackStart (scrolledWindow, true, true, 5);

Gtk.HBox boxinf= new Gtk.HBox();
Gtk.Label lblnthumb = new Gtk.Label("Thumbnail Seleccionado ");
EntradaThumb = new Gtk.Entry();
Gtk.Button bguardar = new Gtk.Button(Stock.Save);
boxinf.PackStart(lblnthumb, false, false, 5);
boxinf.PackStart(EntradaThumb, false, false, 5);
boxinf.PackStart(bguardar, false, false, 5);

box.PackStart(boxinf, false, false, 5);
//Lo agregamos a la ventana
window.Add(box);

//Agregamos las columnas al Treeview
tree.AppendColumn("Miniatura",new Gtk.CellRendererPixbuf(),"pixbuf",0);
Gtk.TreeViewColumn NombreImagenColumna = new Gtk.TreeViewColumn();
NombreImagenColumna.Title = "Nombre de la Imagen";
Gtk.CellRendererText NombreImagenCelda = new Gtk.CellRendererText();
NombreImagenColumna.PackStart(NombreImagenCelda,true);
tree.AppendColumn(NombreImagenColumna.Title, new Gtk.CellRendererText(),"text",1);
tree.AppendColumn("Tipo",new Gtk.CellRendererText(),"text",2);

window.ShowAll();
}

static void OnBCargarClicked(object o, EventArgs args)
{
ImagenLista = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string));
string ndir = EntradaFolder.Text;
string nombreima;
DirectoryInfo dir = new DirectoryInfo(ndir);
FileInfo[] archivos = dir.GetFiles();
for(int i = 0; i < nombreima =" ndir" model =" ImagenLista;" twidth =" Convert.ToInt32(ancho.Text);" theight =" Convert.ToInt32(alto.Text);" pb =" new" thumb =" pb.ScaleSimple" retval="true;" filew =" new" filename = "" text =" filew.Filename;">

No hay comentarios.: