MySQL Forums
Forum List  »  Other Migration

C# - Need to pull BLOB and write to JPG file
Posted by: Steve Link
Date: February 20, 2014 07:26AM

Hi,
I have found C# code that indicates it will pull out a LONGBLOB image and write it to a JPG file. From a logical standpoint this works but it does not create a usable JPG file that can be opened in MSPaint. I can go through HeidiSQL, right-click, and Save BLOB to file to produce a 40k jpg. The C# code produces a 70k jpg for the same image. The code is shown below. Can someone help?
**** code ****
static void Main(string[] args)
{
List<string> linearr = new List<string> { };
string[,] classarr;
int counter = 0;
int x;
string line;
string[] splitln = new string[12];
string inscommand = "";
MySqlConnection conn = new MySqlConnection("SERVER=;Database=;UID=;PASSWORD=");
conn.Open();
Console.WriteLine("Connected to database, importing classexport.txt file");
byte[] fs;
string fnm;
string inppic;
using (MySqlCommand cmd = new MySqlCommand("select Email,ImageFile from employeedirectory;", conn))
{
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
fnm = reader.GetString(0).Substring(0,reader.GetString(0).IndexOf("@"));
if (reader.GetValue(1).ToString() != "")
{
UTF8Encoding enc = new UTF8Encoding();
fs = enc.GetBytes(reader.GetString(1).ToCharArray());
inppic = Convert.ToBase64String(fs);
fs = enc.GetBytes(inppic);
Console.WriteLine(fnm);
File.WriteAllBytes(@"F:\mysql_data\OUPics\" + fnm + ".jpg", fs);
}
}
}
}
conn.Close();
Console.WriteLine("process finished");
}

Options: ReplyQuote


Subject
Views
Written By
Posted
C# - Need to pull BLOB and write to JPG file
7002
February 20, 2014 07:26AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.