hi,
I have a field type image im my MS sql table. It is posible to convert this field to string and later back again to image for viewing. Pls help me. Im stuck for this work.
pls help me.
popskie
Printable View
hi,
I have a field type image im my MS sql table. It is posible to convert this field to string and later back again to image for viewing. Pls help me. Im stuck for this work.
pls help me.
popskie
IMAGE TO STRING?
you're definetly doing something very very wrong.
while it may be possible, it would take up a huge amount of space and it would be stupid. why do you want it to be converted to string?
ok explain it to u. I have a field type which is image. When user user retreive data, the field image is save as string to the listview sub item. then if the user click it will convert string to byte[] in order to veiw the image . I have a code and a class below but there is error invalid paramer used.
// code
strtobyte cl = new strtobyte();
byte[] photo = null;
photo = cl.StrToByteArray(listView1.SelectedItems[0].SubItems[14].ToString()
System.IO.Stream mystream = new System.IO.MemoryStream(photo, true);
mystream.Write(photo, 0, photo.Length);
id.Image = new Bitmap(mystream);
// class
public class strtobyte
{
public byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
public string ByteArraytostr(byte[] Bytes)
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
return enc.GetString(Bytes);
}
}
I'm not sure why it wouldnt work, it might be because of ascii
still you should not need to do that. Are you aware that each listView item has a property called "Tag" where you can assign anything to it. Instead of adding the image to the list item's subitem, set the listitem's tag property to it.
There doesn't seem to be any useful purpose to displaying the image as a string. It would be complete gibberish anyway.
On another note, 90 posts is enough to be familiar with the [code] tags. Please use them to make your code more readable. Also, if you are getting an unhandled exception please specify where exactly it is thrown. We're trying to help you so please don't make us guess.
MrPolite thanks for your great idea it really really works.