Problem encoding/decoding image

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Problem encoding/decoding image

    Hi,

    I'm trying to use POST an image to a web page with WebRequest/WebResponse.
    Only problem is that I must be making an error somewhere in the
    encoding/decoding process. I've pasted below a bit of sample code that
    basically shows how I am encoding and then decoding the binary image. Many
    thanks if you can point out what I am doing wrong... thanks, Slade Smith


    Image bmp =context.GetImage();
    Stream stream=new MemoryStream();

    //save image as a jpg file. "test.jpg" will open fine when I try it....
    bmp.Save("c:\\temp\\test.jpg",System.Drawing.Imagi ng.ImageFormat.Jpeg);
    bmp.Save(stream,System.Drawing.Imaging.ImageFormat .Jpeg);

    //encode the image to prepare it for a transfer via a POST
    int imgLen = (int)stream.Length;
    byte[] imgBinaryData = new byte[imgLen];
    int n = stream.Read(imgBinaryData,0,imgLen);
    string s = Convert.ToBase64String(imgBinaryData);

    //I will be uploading the file here, and the code after this
    //will be running on the server...

    //trying just to reverse the encoding process and save the file,
    //but something has gone horribly wrong, and none of my imaging
    //programs will open "test2.jpg" when I try it. Must be corrupted.
    imgBinaryData=Convert.FromBase64String(s);
    Stream f=File.Create("c:\\temp\\test2.jpg");
    imgLen = imgBinaryData.Length;
    f.Write(imgBinaryData,0,imgLen);
    f.Close();


    Slade Guest

  2. Similar Questions and Discussions

    1. Encoding Problem
      Im pulling an attribute from an XML doc, which is a regexp. The regexp is then used on CFHTTP.filecontent, in order to parse out specfic links from...
    2. MIME::Entity , decoding Base64 image/jpg
      Hi everyone I am trying to decode and extract (image/jpg) attachments from emails/usenet postings. Using MIME::Parser and MIME::Entity->parts(),...
    3. [PHP-DEV] Feature Request - encoding/decoding mail and nntp attachements
      Exo ludo wrote: PHP already has base64 en/decoding. See the manual under base64_encode. I haven't seen any native yEnc extensions, though. ...
    4. [PHP-DEV] Feature Request - encoding/decoding mail and nntp attachements
      Hi, Im lookin for encoding/decoding base64 (and Yenc) attachements in my mail and NNTP programs. After having tested several PHP classes (ex:...
    5. CDONTS - PDF Attachment / decoding problem
      I am using CDONTS to send email from an ASP script. Attached to each of these emails is a 34K PDF file. 90% of the time the file arrives intact....
  3. #2

    Default Re: Problem encoding/decoding image

    Hi,

    Refer to :
    [url]http://www.c-sharpcorner.com/Internet/WebRequestNResponseMDB.asp[/url]

    Using WebClient make it more easier.

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  4. #3

    Default Problem encoding/decoding image

    Hi,

    I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of Encoding and Decoding in ASP.Net and it will help me a lot. I had found another nice post with wonderful explanation on Encoding and Decoding in ASP.Net.

    Thank you very much!
    Ankit Singh Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139