Results 1 to 6 of 6

Thread: [RESOLVED] image field type to string and vice versa

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Resolved [RESOLVED] image field type to string and vice versa

    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

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: image field type to string and vice versa

    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?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: image field type to string and vice versa

    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);
    }


    }
    Last edited by popskie; Aug 25th, 2005 at 11:46 PM.

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: image field type to string and vice versa

    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.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: image field type to string and vice versa

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: image field type to string and vice versa

    MrPolite thanks for your great idea it really really works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width