1

I read several articles on StackOverflow, but none of them seems to work in my case so here is the situation.

I have a webpage that is not under my control. It contains an image that is referenced in the markup as something like <img src="getimage.asp?pic=4c54aae0ea..." />. Given the URL of that image, I would like to download it, save it to disk and do something with it.

When I enter the URL directly in my browser I get a binary stream. This is the first load of characters.

ÿØÿàJFIFHHÿþLEAD Technologies Inc. V1.01ÿÛ„ÿÄ¢       }!1AQa"q2‘¡#B±ÁRÑð$3br‚     %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúw!1AQaq"2B‘¡±Á   #

How do I convert that data to an image using e.g. C# or any other language. Since I do not control the page I have no idea of how the data is encoded - so can I still decode it?

As can be seen from the first couple of characters, the string "LEAD Technologies Inc." is included in the data so I guess its not all image data. But at least, Chrome obviously knows how to decode it. A quick Google check reveals that "LEAD technologies" is an imaging SDK, but their website doesn't seem to offer much information about it's use and Im also not proficient in image manipulation. Any ideas would be appreciated.

4

1 に答える 1

2

最初の数文字は、応答がおそらく ASCII テキストとして解釈される jpeg ファイルであることを示しています。Content-TypeHTTP 応答のヘッダーの値が間違っていると思います。おそらく、text/plainまたはtext/htmlの代わりにのようなものですimage\jpeg。これにより、Chrome は画像をプレーン テキストとして表示します。

データを変換する必要はないと思います。応答ストリームをファイルに保存するだけで、適切な jpeg ファイルが作成されます。

string url = "http://my-domain/getimage.asp?pic=4c54aae0ea...";
string fileLocation = @"C:\MyImage.jpg";

var client = new WebClient();
client.DownloadFile(url, fileLocation);

応答がおそらく jpeg であると思う理由は、エンコードされたテキストとして表示されたときにjpeg ファイルが0xFFD8FFE0次のように見えるためです。ÿØÿàISO 8859-1

于 2013-04-27T20:12:19.897 に答える