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 8139307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:47:04+00:00 2026-06-06T11:47:04+00:00

I have a raw image file that is saved in binary data (no encoding).

  • 0

I have a raw image file that is saved in binary data (no encoding). I want to read in the file and cast the values to an unsigned char. But I’m not sure how to begin going about doing this. Each file contains 640×480 bytes. Each pixel is 8bits.

I’ve used the C++ help page here: http://www.cplusplus.com/doc/tutorial/files/, however when I am couting the data, it seems to be showing the same binary/non-human readable characters. Can someone please advise? Here is my code so far:

    #include <iostream>
    #include <fstream>
    using namespace std;

ifstream::pos_type size;
char * memblock;

int main () {
  ifstream file ("imageData.raw", ios::in|ios::binary|ios::ate);
  if (file.is_open())
  {
    size = file.tellg();
    memblock = new char [size];
    file.seekg (0, ios::beg);
    file.read (memblock, size);

    cout << "the complete file content is in memory";

    for (int l=0; l<size; l++){
    cout << " memblock[] is = " << (unsigned char)memblock[l] << " index was l = " << l << endl;
    }

    file.close();


    delete[] memblock;
  }
  else cout << "Unable to open file";
  return 0;
}

Here is a sample capture of the output:

 memblock[] is = ▀ index was l = 2937
 memblock[] is = E index was l = 2938
 memblock[] is = τ index was l = 2939
 memblock[] is = C index was l = 2940
 memblock[] is = ┘ index was l = 2941
 memblock[] is = B index was l = 2942
 memblock[] is = ╬ index was l = 2943
 memblock[] is = D index was l = 2944
 memblock[] is = ┼ index was l = 2945
 memblock[] is = C index was l = 2946
 memblock[] is = ╝ index was l = 2947
 memblock[] is = B index was l = 2948
 memblock[] is = ┤ index was l = 2949
 memblock[] is = B index was l = 2950
 memblock[] is = ¿ index was l = 2951
 memblock[] is = > index was l = 2952
 memblock[] is = í index was l = 2953
 memblock[] is = ; index was l = 2954
 memblock[] is = £ index was l = 2955
 memblock[] is = 6 index was l = 2956
 memblock[] is = á index was l = 2957
 memblock[] is = 4 index was l = 2958
 memblock[] is = Ñ index was l = 2959
 memblock[] is = 7 index was l = 2960
 memblock[] is = ╡ index was l = 2961
  • 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-06T11:47:05+00:00Added an answer on June 6, 2026 at 11:47 am
    unsigned char* memblock; // change declaration of memblock
    
    ...
    
    memblock = new unsigned char[size]; // change to unsigned char
    file.seekg (0, ios::beg);
    file.read ((char*)memblock, size); // cast to a char* to give to file.read
    

    To print numeric values instead of characters, cast to an int before printing.

    (int) memblock[l]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image file that is a grayscale 8 bit unsigned integer raw
I have written a raw binary image file into a buffer which is an
I have raw data in a custom image format (canot be changed) that is
I have an raw image file that is .bin and is composed of 16
I have a raw image where each pixel corresponds to a 16 bits unsigned
I have a raw form-data that look like this: ------------V2ymHFg03ehbqgZCaKO6jy Content-Disposition: form-data; name=intro O
I have some automated test (using CUnit) which require a disk-image-file (raw copy of
I have a export script that export items to a csv file. I want
I have a raw image buffer in the RGB format. I need to draw
You have 2000 raw images, 52x52 pixels, RGB 24 bits, that correspond to the

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.