Re: imagenes en postgres

From: "Yoel Mc Lennan" <listas(at)yoel(dot)com(dot)ar>
To: "cesar florez" <cesarflorezdiaz(at)yahoo(dot)es>, <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: imagenes en postgres
Date: 2009-12-28 22:23:01
Message-ID: 004d01ca880c$5332e570$8202a8c0@YoelEsc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

En C# ,hay que convertir la imagen a un array de bytes para grabarlo en bytea, quizá esto te pueda servir.

saludos.

public static byte[] Image2Bytes(Image img)

{

string sTemp = Path.GetTempFileName();

FileStream fs = new FileStream(sTemp, FileMode.OpenOrCreate, FileAccess.ReadWrite);

img.Save(fs, System.Drawing.Imaging.ImageFormat.Png);

fs.Position = 0;

//

int imgLength = Convert.ToInt32(fs.Length);

byte[] bytes = new byte[imgLength];

fs.Read(bytes, 0, imgLength);

fs.Close();

return bytes;

}

public static byte[] ImagenABytes(Image Imagen)

{

Bitmap bmp = new Bitmap(Imagen);

MemoryStream mm = new MemoryStream();

bmp.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);

ImageConverter converter = new ImageConverter();

byte[] Array = (byte[])converter.ConvertTo(bmp, typeof(byte[]));

return Array;

}

public static Image Bytes2Image(byte[] bytes)

{

if (bytes == null) return null;

//

MemoryStream ms = new MemoryStream(bytes);

Bitmap bm = null;

try

{

bm = new Bitmap(ms);

}

catch (Exception ex)

{

System.Diagnostics.Debug.WriteLine(ex.Message);

}

return bm;

}

----- Original Message -----
From: cesar florez
To: pgsql-es-ayuda(at)postgresql(dot)org
Sent: Monday, December 28, 2009 1:53 PM
Subject: [pgsql-es-ayuda] imagenes en postgres

estoy desarrollando una aplicacion en Visual c++ 6.0 y la version de postgresql que estoy utilizando es la 8.4 bajo windows he tratado de insertar una imagen en base de datos y he intentado por todos los medios pero sin nungun resultado, he probado con el tipo de datao bytea, y con el oid con el oid funciona pero no con el resultado esperado, donde tengo entendido el tipo oid guarda un identificador donde se encuentra la imagen mas no insertera el contenido a la tabla.

Nota.
me conecto con el servidor usando las api de postgres que viene libreria pqlib.lib

les agradeceria muchisimo cual quier informacion que me pueda ayudar..
Gracias...

Att. Cesar Flórez

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2009-12-29 00:11:06 Re: Problemas para instalar el psql ODBC para un equipo con Windows 7 Home Basic de 64 bits.
Previous Message Luis Esteban 2009-12-28 22:10:37 Re: campo tipo text...