473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Read in image ... get ascii values

175 100+
I want to read in an image file ( bmp, jpeg, ... ) so I can retain it's ascii / binary values, and alter the image. How can I do this in C++ ( I'm using Visual Studio, various versions ).


so basically, I want to make a big matrix of values in an array.


I know this can be done using a hex editor, but in C++ I'm not sure how to get the ascii values. Any help is appreciated.
Sep 4 '08 #1
10 6033
boxfish
469 Expert 256MB
Hi,
I don't quite understand this question. You're trying to read a file into an array, so can you just make an array of chars and read into that? The binary and ASCII values would be retained, right? I don't see what you need to do with ASCII values.
Sep 4 '08 #2
manontheedge
175 100+
The reason I want to get the actual values is because in my code I want to be able to change the color of the image (by changing the ascii values) and output that image with my changes.
Sep 4 '08 #3
boxfish
469 Expert 256MB
chars store the ASCII values of the characters you put into them. If you read the file into an array of chars, then you will have the ASCII values of all the characters in the file, and you can work with them just as if they were ints.
Sep 4 '08 #4
manontheedge
175 100+
I understand the concept ... what I'm asking is HOW to read in an image file so that I CAN get the ascii values.

when I try to read it in by line or by character, it only gives one total ascii digit, ONE, there should be thousands ... so my problem is reading it IN, not working with the values, I have no problem with that
Sep 5 '08 #5
Laharl
849 Expert 512MB
Can you show us the code you use to read the file in? We're (unfortunately) neither clairvoyant nor telepathic.
Sep 5 '08 #6
manontheedge
175 100+
sure, essentially ( off the top of my head ), the code I'm using is ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. ...
  3. #include <fstream>
  4. ...
  5.  
  6.  
  7. readFile()
  8. {
  9.     ifstream in;
  10.     in.open( "C:\Documents and Settings\ ... \ image.jpg" );
  11.  
  12.     char data[80];
  13.  
  14.     while( in.good() )
  15.     {
  16.         in.getline( data, 80 );
  17.         cout << atoi( data ) << endl;
  18.     }
  19.  
  20.     in.close();
  21. }
  22.  
  23.  
that's basically the idea ... however, I have a feeling this isn't the way to read in images, so that's why I first asked the question ... I appreciate the responses.
Sep 5 '08 #7
boxfish
469 Expert 256MB
The code you posted won't work because:
1: Every line after the first line gets written over the previous line. You readline the line into data, and then the next iteration of the loop, you readline right over it again. It's probably better to read into a vector or dynamic array than a static array, because image files can be huge. You could push_back all the bytes into a char vector with the ifstream::get function.
2: The way you're outputting the ASCII values is wrong; the atoi function takes a c-string such as "8132" and converts it to the int value 8132. Instead, loop through all the characters in data, and for each one, static_cast it to an int and output it.
Hope this helps.
Sep 5 '08 #8
Banfa
9,065 Expert Mod 8TB
The should be no mention of ASCII when reading data from an image file. ASCII is purely one of serveral ways of interpreting binary data as text.

With an image file there is no text just binary data representing coloured pixels.

You MUST open the file in binary or you WILL get corruption of the data.

You should not attempt to read the file as though it were text (i.e. by using getline), you should read it as the thing it is, binary data.
Sep 5 '08 #9
manontheedge
175 100+
I'm not reading into an array and overwriting it ... I just typed that code to give an idea of what I was doing, but thank you for that.

Banfa, that was what I was looking for, whenever I read the file, it came out as either garbage or nothing. Thank you.
Sep 5 '08 #10
If u want to open and do sum opeartion in a image file , better open it in a Binary modde ... open ("image.jpg", b) ..


Try this ...
Sep 10 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Randy Webb | last post by:
Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can have PHP read an image file and out put its color content? Preferably, I would like for it to read a .bmp file and output a...
2
by: John Bowling | last post by:
I'm trying to read a file that contains text for a decimal count, convert it to binary, increment and write it back out. I'm using Java 2 in SuSE 8.2, installed from the SuSE CD's. When using...
14
by: George Hester | last post by:
http://hesterloli.dnsalias.com/test/javascript_image.htm The image is the 100x100 px block. If we right-click in it and try to save the image we cannot. Is it possible to say set a mime-type so...
0
by: Anonieko Ramos | last post by:
> I have a graphics images that I want to convert to > ASCII art. How do I do it? > Code: - Default.aspx.cs
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
2
by: Chris3000 | last post by:
All i wanna do is simple, I wanna display an image from an access database. I try alot of things to no result. Like ascii code or nothing but a blank image with a red 'X'. Here is the code : ...
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
3
by: sam | last post by:
same as subject?
5
by: siddhanta | last post by:
hi, i read the ascii value from a file and wrote the decimal one in other file. But values above "127" i.e. extended ascii are printed as" 65533." here ais wat i did: private void...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.