Click here to Skip to main content
15,884,684 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
It's been many years since I last did any C++ coding.
I'm writing in VS unmanaged C++.

This is probably a pretty basic question.

How do I read either a bitmap or jpeg file into a byte array?
(Byte is typedef'd as "unsigned char")

Thanks,
JohnB
Posted
Comments
Sergey Alexandrovich Kryukov 14-Dec-14 20:41pm    
It depends on what do you want to have in that array. If you want array of pixels, it should be array of pixel values in one of the pixel formats, not bytes...
—SA

Read this article.

You must at first allocate a buffer which is big enough for the file data and than read it in.

If you work with the jpeg the great article Imagestone may help you.
 
Share this answer
 
You may read every file data into a byte buffer simply using standard ifstream facilities (on Windows you have to use the "binary mode").
On the other hand, if you need to extract info (e.g. pixel colors) from an image file then you have to use a specific API (e.g. the one provided by GDI+).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900