473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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();
Nov 17 '05 #1
1 2645
Hi,

Refer to :
http://www.c-sharpcorner.com/Interne...esponseMDB.asp

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 http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthias Stern | last post by:
Hello! I've got a Javascript-PHP encoding problem. (1) Here is the short version: ============================== I'm sending a form textfield via Javascript(!) as URL parameter (GET)...
3
by: dot | last post by:
Hi all, I have written a Python huffman Encoding Module, for my own amusement. I thought it might be educational/entertaining for other people, so I've put it on my website and wrote about it a...
8
by: timtos | last post by:
I want to save text in a file and after that I want to display this textfile using the internet explorer. If I am displaying "html text" everything is fine but if I want to display plain text...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
9
by: KWSW | last post by:
Having settled the huffman encoding/decoding and channel modeling(thanks to the previous part on bitwise operation), the last part would be hamming encoding/decoding. Did some research as usual on...
0
by: Independent | last post by:
Python programmers may find the application to decoding an encrypted map image format known as Memory Map to produce a standard PNG image file interesting. Someone obviously very well versed in...
0
by: james.duckworthy | last post by:
Python programmers may find the application to decoding an encrypted map image format known as Memory Map to produce a standard PNG image file interesting. Someone obviously very well versed in...
0
by: Michele | last post by:
Hi there, I'm using a python script in conjunction with a JPype, to run java classes. So, here's the code: from jpype import * import os import random import math import sys
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.