| |

VerySource

 Forgot password?
 Register
Search
View: 687|Reply: 5

Simple question, help!

[Copy link]

1

Threads

5

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-3 16:30:01
| Show all posts |Read mode
A CHttpFile object gets a JPG image from the specified URL.
problem:
How can I save her? How to show her?
Reply

Use magic Report

1

Threads

5

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-1-3 20:39:01
| Show all posts
It is the following code, the saved picture cannot be displayed normally. Where is the problem?
===========================================
CInternetSession sess;
CHttpFile * pFile = (CHttpFile *) sess.OpenURL (pstrURL, 1, INTERNET_FLAG_TRANSFER_ASCII || INTERNET_FLAG_RELOAD, headers, strlen (headers));
char buffer [1024];
CStdioFile file;
file.Open ("C:\\aaa.jpg", CFile :: modeWrite | CFile :: modeCreate);
while (pFile-> Read (buffer, sizeof (buffer)))
{
file.Write (buffer, sizeof (buffer));
}
Ranch
file.Close ();
pFile-> Close ();
sess.Close ();
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-3 21:54:02
| Show all posts
CFile file;
file.Open ("C:\\aaa.jpg", CFile :: modeWrite | CFile :: modeCreate);
                   int nRead;
while ((nRead = pFile-> Read (buffer, sizeof (buffer))))
{
file.Write (buffer, nRead);
}
Reply

Use magic Report

1

Threads

5

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-1-3 21:57:01
| Show all posts
always_wy:
This will not work. nRead is not initialized, it will report an error.
Reply

Use magic Report

1

Threads

5

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-1-3 23:36:01
| Show all posts
always_wy:

Still no, no error, but the picture still does not display properly.
Reply

Use magic Report

1

Threads

5

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-1-3 23:45:01
| Show all posts
nailed it. Thank youalways_wy: You are right!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list