Skip to content

Instantly share code, notes, and snippets.

@defaultlocale
Created September 3, 2018 12:21
Show Gist options
  • Save defaultlocale/1877bad08ee71f5b2a97b3eaf026ba5f to your computer and use it in GitHub Desktop.
Save defaultlocale/1877bad08ee71f5b2a97b3eaf026ba5f to your computer and use it in GitHub Desktop.
Oracle TIFF image query
using System.Drawing;
using System.IO;
using Oracle.ManagedDataAccess.Client;
namespace OracleTiffImage
{
static class Program
{
private const string CONNECTION_STRING = "data source=DB;user id=USER;password=\"password\";pooling=false";
static void Main()
{
using (var cn = new OracleConnection(CONNECTION_STRING))
{
var imgCmd = new OracleCommand("select SIGNATURE from image_table", cn)
{
InitialLONGFetchSize = -1
};
cn.Open();
var reader = imgCmd.ExecuteReader();
if (reader.Read())
{
var imgBinary = reader.GetOracleBinary(0);
var imgBytes = imgBinary.Value;
var stream = new MemoryStream();
stream.Write(imgBytes, 0, imgBytes.Length);
var bm = new Bitmap(stream);
bm.Save("d:\\image.tif", System.Drawing.Imaging.ImageFormat.Tiff);
}
reader.Close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment