| |

VerySource

 Forgot password?
 Register
Search
View: 729|Reply: 2

[Novice help] Please help read a piece of code about reading pictures from the database

[Copy link]

5

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-19 13:20:01
| Show all posts |Read mode
Here is the code that displays the picture:

1 object result = cmd.ExecuteScalar ();
2 Stream stream = new MemoryStream ((byte []) result);
3 const int buffersize = 1024 * 16;
4 byte [] buffer = new byte [buffersize];
5 int count = stream.Read (buffer, 0, buffersize);
6 while (count> 0)
7 {
8 Response.OutputStream.Write (buffer, 0, count);
9 count = stream.Read (buffer, 0, buffersize);
10}

Why does line 3 use the constant buffersize = 1024 * 16?

If any big brother has time, can you tell me more about the meaning of this code? For example, I don't understand the second line.

Or is there any other way to display the picture (image type) in the database?

Thank you, thank you very much! ~
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-27 21:09:02
| Show all posts
// Convert result to a binary byte array and create a stream
            stream = new MemoryStream ((byte []) result);
           
            const int buffersize = 1024 * 16;
            byte [] buffer = new byte [buffersize];
           
            // Write photo content to binary byte array Buffer
            int count = stream.Read (buffer, 0, buffersize);
           
            // Output the contents of the Buffer to the page through a loop statement
            while (count> 0)
            {
                Response.OutputStream.Write (buffer, 0, count);
                count = stream.Read (buffer, 0, buffersize);
            }
Reply

Use magic Report

0

Threads

10

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-9 15:00:02
| Show all posts
buffersize = 1024 * 16 should be the size of the picture is 1024byte * 16 = 16K
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