Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

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: Mon, 28 Dec 2009 19:23:01 -0300
  • Message-id: <004d01ca880c$5332e570$8202a8c0@YoelEsc> <text/plain>

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

     



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group