Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:17:54+00:00 2026-06-09T07:17:54+00:00

I am trying to chunk up the bytes of an image. This will allow

  • 0

I am trying to “chunk” up the bytes of an image. This will allow me to upload a large image in portions. I have the image currently stored as one large byte[]. I would like to split the byte array into byte[]‘s with a maxlength of 512 elements. However, I’m not sure how to do this in the most efficient way.

Does anyone know how I can do this in the most efficient manner?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:17:55+00:00Added an answer on June 9, 2026 at 7:17 am

    The most efficient method would be: not to. If you already have the image as a single byte[] then for local code, just specifying the offset and length (perhaps som ArraySegment-of-byte) is usually sufficient. If your upload API only takes byte[], then you still shouldn’t chunk it completely; just use a single 512 buffer and use Buffer.BlockCopy to load it will successive pieces of the data. You may need to resize (Array.Resize) the final chunk, but at most 2 arrays should be needed.

    Even better; avoid needing a byte[] in the first place: consider loading the data via a streaming API (this will work well if the data is coming from a file); just use Read (in a loop, processing the returned value etc) to populate chunks of max 512. For example (untested, just of illustration):

    byte[] buffer = new byte[512];
    while(true) {
        int space = 512, read, offset = 0;
        while(space > 0 && (read = stream.Read(buffer, offset, space)) > 0) {
            space -= read;
            offset += read;
        }
        // either a full buffer, or EOF
        if(space != 0) { // EOF - final
           if(offset != 0) { // something to send
             Array.Resize(red buffer, offset);
             Upload(buffer);
           }
           break;
        } else { // full buffer
           Upload(buffer);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string containing a large chunk of html and am trying to
I'm trying to streamline large chunk of legacy C code in which, even today,
This is a chunk of javascript code from a tutorial where they are trying
I'm trying to copy a chunk from one binary file into a new file.
I have an NSData object with a chunk of binary data and I'm trying
I'm trying to understand how data are stored into IDAT chunk. I'm writing a
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char
I am trying to empower users to upload large files. Before I upload a
I'm trying to reuse a small chunk of code inside a custom button class.
Following chunk html code works as expected: <iframe src=http://www.amazon.com/></iframe> But when trying embed inner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.