473,382 Members | 1,329 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,382 software developers and data experts.

PNG image from website -> picture box (using sockets)

I've got a small sockets application where I communicate with a web server
via async sockets method.

Using the ASCIIEncoding Class, I convert strings to byte arrays (and vice
versa) in conjunction with beginSend and beginReceive (and their
corresponding callbacks). So long as the web server and I just deal in
text, life is easy.

Now there's an image I want to request and then display in my app, it's a
dynamic PNG image that's generated by some .aspx page on the web server. So
my GET, to request this image, looks like this:

GET /MakeThePNG.aspx HTTP/1.1
Host: www.url.com
And here's the website's response:

HTTP/1.1 200 OK
Date: Thu, 01 Dec 2005 20:28:01 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Transfer-Encoding: chunked
Cache-Control: private, max-age=1800
Content-Type: image/png

39c9
?PNG
<a bunch of data>
0
I need to turn this response (sans the header, I'm assuming, but I'm unsure
which portions of the body) into an image object that I can display in a
picture box & save to disk. I've tried messing around with a Memory Stream,
and with that, tried including the whole body portion, just the <a bunch of
data> portion, but my attempts thus far are ultimately met with an Invalid
Argument exception when I try to make a new Image.FromStream with my Memory
Stream. I've tried to save said portions of the buffer to disk, but it does
not make a valid png file. So I'm not carving the data out of the body
correctly, or, it's not encoded correctly, or... ? I'm stumped.
Dec 1 '05 #1
2 2068
Ok, the answer was to read up on how PNGs are put together.

http://www.w3.org/TR/PNG/

PNGs start with with 8 "signature" bytes, 137 80 78 71 13 10 26 10. Those
are the first 8 bytes of the PNG file.

PNGs end with an "IEND" chunk, literally "IEND" (73 69 78 68), followed by 4
more bytes (CRC portion of the chunk). Those are the last 8 bytes of the
PNG file.

As soon as I exctracted the bytes from the Signature to the IEND chunk
(inclusive) and fed it to a memory stream, thus correctly carving out the
whole PNG file and nothing but the PNG file, Image.FromStream magically
turned the memory stream into an image.
"1388-2/HB" <1@1.net> wrote in message
news:43**********************@news.usenetmonster.c om...
I've got a small sockets application where I communicate with a web server
via async sockets method.

Using the ASCIIEncoding Class, I convert strings to byte arrays (and vice
versa) in conjunction with beginSend and beginReceive (and their
corresponding callbacks). So long as the web server and I just deal in
text, life is easy.

Now there's an image I want to request and then display in my app, it's a
dynamic PNG image that's generated by some .aspx page on the web server.
So my GET, to request this image, looks like this:

GET /MakeThePNG.aspx HTTP/1.1
Host: www.url.com
And here's the website's response:

HTTP/1.1 200 OK
Date: Thu, 01 Dec 2005 20:28:01 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Transfer-Encoding: chunked
Cache-Control: private, max-age=1800
Content-Type: image/png

39c9
?PNG
<a bunch of data>
0
I need to turn this response (sans the header, I'm assuming, but I'm
unsure which portions of the body) into an image object that I can display
in a picture box & save to disk. I've tried messing around with a Memory
Stream, and with that, tried including the whole body portion, just the <a
bunch of data> portion, but my attempts thus far are ultimately met with
an Invalid Argument exception when I try to make a new Image.FromStream
with my Memory Stream. I've tried to save said portions of the buffer to
disk, but it does not make a valid png file. So I'm not carving the data
out of the body correctly, or, it's not encoded correctly, or... ? I'm
stumped.

Dec 1 '05 #2
why dont you just use a HTTP stream and read it as binary?! its so much
easier

"1388-2/HB" <1@1.net> wrote in message
news:43**********************@news.usenetmonster.c om...
Ok, the answer was to read up on how PNGs are put together.

http://www.w3.org/TR/PNG/

PNGs start with with 8 "signature" bytes, 137 80 78 71 13 10 26 10. Those
are the first 8 bytes of the PNG file.

PNGs end with an "IEND" chunk, literally "IEND" (73 69 78 68), followed by
4 more bytes (CRC portion of the chunk). Those are the last 8 bytes of
the PNG file.

As soon as I exctracted the bytes from the Signature to the IEND chunk
(inclusive) and fed it to a memory stream, thus correctly carving out the
whole PNG file and nothing but the PNG file, Image.FromStream magically
turned the memory stream into an image.
"1388-2/HB" <1@1.net> wrote in message
news:43**********************@news.usenetmonster.c om...
I've got a small sockets application where I communicate with a web
server via async sockets method.

Using the ASCIIEncoding Class, I convert strings to byte arrays (and vice
versa) in conjunction with beginSend and beginReceive (and their
corresponding callbacks). So long as the web server and I just deal in
text, life is easy.

Now there's an image I want to request and then display in my app, it's a
dynamic PNG image that's generated by some .aspx page on the web server.
So my GET, to request this image, looks like this:

GET /MakeThePNG.aspx HTTP/1.1
Host: www.url.com
And here's the website's response:

HTTP/1.1 200 OK
Date: Thu, 01 Dec 2005 20:28:01 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Transfer-Encoding: chunked
Cache-Control: private, max-age=1800
Content-Type: image/png

39c9
?PNG
<a bunch of data>
0
I need to turn this response (sans the header, I'm assuming, but I'm
unsure which portions of the body) into an image object that I can
display in a picture box & save to disk. I've tried messing around with
a Memory Stream, and with that, tried including the whole body portion,
just the <a bunch of data> portion, but my attempts thus far are
ultimately met with an Invalid Argument exception when I try to make a
new Image.FromStream with my Memory Stream. I've tried to save said
portions of the buffer to disk, but it does not make a valid png file.
So I'm not carving the data out of the body correctly, or, it's not
encoded correctly, or... ? I'm stumped.


Dec 6 '05 #3

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

Similar topics

5
by: OneSolution | last post by:
Hi All, Here's what I'm trying to do. I have a diverse customer base, and as it grows, it's increasingly harder to figure out what aspect of our web site is selling and what is not. So I've...
9
by: yawnmoth | last post by:
i've written a php script that generates images dynamically, via the GD library. i now want to detect whether or not the image is embedded within a homepage, or is being viewed by itself. at...
2
by: Suzanne Boyle | last post by:
I have the following code in a webpage: <p><img src="images/clydesdale.gif" width="100" height="41" style="float: left;" /> <strong>Test</strong><br /> Lorem ipsum dolor sit amet, consetetur...
8
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client...
13
by: lkrubner | last post by:
Suppose I need to get an image as a stream of bytes. I want to store this in a variable and then embed it in some Postscript code. In my Postscript code, the image might look like this: {<...
0
by: Geert | last post by:
Hi all, I have a webservice that creates an image. I want to show the result of that image on my website. The website and webservice are on different servers. There is a VPN line between both...
4
by: rh1200la | last post by:
Hey all. I need to output an image via an .aspx page and hope someone here can help. I would like to display an image like this: <img src="displayImage.aspx?categoryID=1"> The .aspx page...
7
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. I have an ASP.NET 2.0 web application which contains an Images directory with all website images. How can I prevent other websites from creating img tags with the source as my images? I want...
12
by: lawpoop | last post by:
I'm developing a php website that I have under subversion version control. I'm working on an image upload functionality, and in the middle of it I realized that any files that a user uploads will...
8
by: jeddiki | last post by:
Hi, I am giving cleints an image to use as a kind of "trust seal" and I want to record the number of times it is diplayed, is that possible with php, of is this a javascript project ? This...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.