read image from url

Q

quickcur

hi can anyone explain me to read image to memory from a url

it is very easy in java but it is hard to find an complete
solution in c/c++.

Thanks,
 
V

vippstar

hi can anyone explain me to read image to memory from a url

it is very easy in java but it is hard to find an complete
solution in c/c++.

Thanks,


Cannot be done.
 
J

jacob navia

quickcur said:
hi can anyone explain me to read image to memory from a url

it is very easy in java but it is hard to find an complete
solution in c/c++.

Thanks,

This is beyond the scope of standard C since standard C can't do much
in this domain (network+graphics)

That said, you can do that in two lines of C if you use
lcc-win under windows.
1) You get the image into a local file with the function
gethttputrl
2) You "execute" the image after downloading it with "shell execute"
and the windows shell will call the program that is associated
with that type of image and display it in the screen.

Done
 
R

Richard Heathfield

quickcur said:
hi can anyone explain me to read image to memory from a url

Using a library such as libcurl will make this much simpler, but there's
nothing inherently difficult about it anyway. Open a socket (consult a
platform-specific group for details on that), do the HTTP protocol (see
the relevant RFC), and start grabbing the data and stuffing it into
memory. Don't forget to be ready to realloc if you underestimated how much
storage you need for the image.
it is very easy in java but it is hard to find an complete
solution in c/c++.

Why do you think it's easy in Java? The chances are good that it's because
your Java implementation invokes a C library to fetch the data on its
behalf.
 
S

santosh

quickcur said:
hi can anyone explain me to read image to memory from a url

it is very easy in java but it is hard to find an complete
solution in c/c++.

Thanks,

One solution is to use a library like libcurl. But if that is not
available on your system, then you need to find the platform's native
APIs that implement networking. Using libcurl is much easier that doing
it yourself. With static linking you could distribute your application
to users who do not have libcurl.

For further details post to a relevant group like
<or
<or whichever group deals with your platform.
 
Q

quickcur

This is beyond the scope of standard C since standard C can't do much
in this domain (network+graphics)

That said, you can do that in two lines of C if you use
lcc-win under windows.
1) You get the image into a local file with the function
gethttputrl
2) You "execute" the image after downloading it with "shell execute"
and the windows shell will call the program that is associated
with that type of image and display it in the screen.

Done

Dear Jacob-

Thanks for your answer. Can you tell me how to get lcc-win? Is it a
library for Windows only?

Thanks.

PS. Can gethttputrl get the image directly to a memory buffer as well as
to a local file?
 
V

vippstar

Do we a favor and go away


Notice the subject of this newsgroup is ISO C.
ISO C has not defined 'url' and the such.
Please try another platform-specific newsgroup.
 
J

jacob navia

quickcur said:
Dear Jacob-

Thanks for your answer. Can you tell me how to get lcc-win? Is it a
library for Windows only?

Thanks.

PS. Can gethttputrl get the image directly to a memory buffer as well as
to a local file?

lcc-win is a compiler system for windows (32 and 64 bits).
The gethttputrl function is part of the netutils.lib
#include <netutils.h>
int GetHttpUrl(char *URL,char *localfilename);

You can download lcc-win at the url below
 
K

Keith Thompson

jacob navia said:
This is beyond the scope of standard C since standard C can't do much
in this domain (network+graphics)

That said, you can do that in two lines of C if you use
lcc-win under windows.
1) You get the image into a local file with the function
gethttputrl
2) You "execute" the image after downloading it with "shell execute"
and the windows shell will call the program that is associated
with that type of image and display it in the screen.

quickcur: Don't assume that lcc-win provides the only solution for
this. Most C implementations will provide, or can be used with,
libraries that can perform network operations. The only problem is
that no such libraries are defined in standard C, so you'll get better
answers if you ask in a system-specific newsgroup.

Incidentally, jacob, your response doesn't really answer the OP's
question. He asked how to read an image into memory. You explained
how to download an image and invoke an external program on it, which
is not the same thing at all. (Once you've downloaded it to a file,
you can read it into memory using standard file handling functions.)
But if the goal is to get the data into memory, it may not be
necessary to copy it to a file first; it's likely that you can read it
directly into memory from the network connection.
 
Q

quickcur

lcc-win is a compiler system for windows (32 and 64 bits).
The gethttputrl function is part of the netutils.lib
#include <netutils.h>
int GetHttpUrl(char *URL,char *localfilename);

You can download lcc-win at the url below

Dear Jacob-

Thanks for the advice.

I downloaded and installed lcc-win but experienced a few problems.
Firstly when I run it I keep getting messages "lcc.exe has encountered a
problem and needs to close. We are sorry for the inconvenience." It
doesn't actually close, but it's quite annoying. Also copy and paste
doesn't work.

Anyway, I think I may have a linking problem. I tried adding -lnetutils
to the linker flags in Project->Configuration, but it still doesn't link
properly. The test code is below.


/* --- The following code comes from C:\lcc\lib\wizard\textmode.tpl. */
#include<netutils.h>
int GetHttpUrl(char *URL, char *localfilename);

void main()
{
// gethttputrl("http://www.google.com/logos/holiday07_3.gif",
"c:\test.gif");
GetHttpUrl("http://www.google.com/logos/holiday07_3.gif", "c:\test.gif");
}


Here is the error message:

Error c:\lcc\projects\hello\src\hello.c 8 undefined reference to _GetHttpUrl
c:\lcc\bin\make.exe
Compilation + link time:0.1 sec, Return code: 1
 
J

jacob navia

quickcur wrote:
[snip
The correct name is
GetHttpURL

(note URL with UPPER CASE

Excuse me for this error!
 
J

jacob navia

quickcur said:
Dear Jacob-

Thanks for the advice.

I downloaded and installed lcc-win but experienced a few problems.
Firstly when I run it I keep getting messages "lcc.exe has encountered a
problem and needs to close. We are sorry for the inconvenience." It
doesn't actually close, but it's quite annoying. Also copy and paste
doesn't work.

Anyway, I think I may have a linking problem. I tried adding -lnetutils
to the linker flags in Project->Configuration, but it still doesn't link
properly. The test code is below.


/* --- The following code comes from C:\lcc\lib\wizard\textmode.tpl. */
#include<netutils.h>
int GetHttpUrl(char *URL, char *localfilename);

void main()
{
// gethttputrl("http://www.google.com/logos/holiday07_3.gif",
"c:\test.gif");
GetHttpUrl("http://www.google.com/logos/holiday07_3.gif",
"c:\test.gif");
Please do not write to the root of drive C!!!!

Use another directory since writing to the drive C will
make the program crash under vista.

Please send me any problems to the mail address below
and you will get a prompt answer.

Do not send it to the group since it is compiler specific
 
K

Keith Thompson

quickcur said:
Dear Jacob-

Thanks for the advice.

I downloaded and installed lcc-win but experienced a few
problems.
[...]

If you're having problems with lcc-win, please ask about them in
comp.compilers.lcc, or perhaps by sending e-mail directly to jacob.
comp.lang.c is for discussion of the C programming language.

[...]
void main()
[...]

The correct declaration is "int main(void)". That's not likely to be
the source of your problem, but you should fix it anyway.
 
Q

quickcur

Please do not write to the root of drive C!!!!

Use another directory since writing to the drive C will
make the program crash under vista.

It's OK, I have administrator priviledges on my development box. I don't
think that's the problem, I think it's a linking problem... with the
capital URL I still get
Error c:\lcc\projects\hello\src\hello.c 8 undefined reference to
What are the right linking flags?

By the way, I normally use Visual C/C++. Is there a way to make the
netutils.lib into a DLL that I can install in Windows\System32 and use
as normal?

Thanks.
 
T

Tim Smith

Why do you think it's easy in Java? The chances are good that it's because
your Java implementation invokes a C library to fetch the data on its
behalf.

It's easy in Java because the functions to do it are part of the
standard libraries that are available in all Java implementations.
(Well, all normal Java implementations...they might be missing from the
version of Java that is meant for very small devices).

Basically, it is something like this:

URL foo = new URL("http://example.org/whatever.html");
BufferedReader in = new BufferedReader(
new InputStreamReader(
foo.openStream()));

and then you can read lines from that URL with in.readLine(), or use any
of the other functions for reading input from a buffered stream.

There's nothing inherent about Java the language that makes this easy.
It is just that Java does have an unusually expansive standard library
compared to, say C, so a lot of things that you either do yourself in C,
or have to go hunting down a third-party library for, are already in the
Java libraries.
 
K

Keith Thompson

quickcur said:
On 23/12/2007 20:05, jacob navia wrote: [...]
Please send me any problems to the mail address below
and you will get a prompt answer.

Do not send it to the group since it is compiler specific
[...]

Please pay attention to what jacob wrote. Your questions are
inappropriate for comp.lang.c.
 
Q

quickcur

On 23/12/2007 20:05, jacob navia wrote:
[...]
Please send me any problems to the mail address below
and you will get a prompt answer.

Do not send it to the group since it is compiler specific

[...]

Please pay attention to what jacob wrote. Your questions are
inappropriate for comp.lang.c.

Why???

Well whatever, I think I'll look for another solution. lcc-win seems
very unstable and buggy, and the library won't work with Microsoft
Visual C/C++.
 
J

jacob navia

quickcur said:
On 23/12/2007 20:05, jacob navia wrote:
[...]

Please send me any problems to the mail address below
and you will get a prompt answer.

Do not send it to the group since it is compiler specific

[...]

Please pay attention to what jacob wrote. Your questions are
inappropriate for comp.lang.c.

Why???

Well whatever, I think I'll look for another solution. lcc-win seems
very unstable and buggy, and the library won't work with Microsoft
Visual C/C++.


I compiled this:

#include <netutils.h>
int GetHttpUrl(char *URL, char *localfilename);

int main(void)
{
GetHttpURL("http://www.google.com/logos/holiday07_3.gif", "test.gif");
}

The command line is:

lc tnet.c netutils.lib winhttp.lib

and I have a gif in my current directory containing the logo of
google.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,243
Latest member
Weeb3PRAgency

Latest Threads

Top