how to insert an image?

when we make a simple program, the background is always black.
how we insert an image or picture as a background? or just change the background color?
what code shall we use? example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream.h>
using namespace std;

int main() {
  int x, y;
  cout<<"what is your height?"<<"\nyour feet: ";
  cin>>x;
  cout<<"your inches: ";
  cin>>y;
  cout<<"your height is: "<<x<<"'"<<" and "<<y<<"''";
  cout<<"\nYou are tall!";

  return 0;
}


how to insert an image as a background? or just change color..
thanks in advance.. ΓΌ
You can't draw images in console. You can however change the font/ background color.

The wrong way:
system("color fc"); sets text color as red and background color as white. Note that color will be changed i the whole console. Also, system isn't quite save.

The windows way:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xfc); same color, but now, only text printed after this function was called will be colored. This allows multiple colors.

edit:
And now I'll explain how the colors work. You'll probably just google which color is which, but you migt find this interesting. Attribute is kept in a byte. 4 bits for background and 4 for text color. To represent this color hexadecimal numbers are used, since one hex digit represents 4 bits. For example 0x07. 0 is background color (black) and 7 is text color (gray).

If you write the 4 bits in binary they represent red, green and blue components. The first bit indicates whether the color is bright or dark.
examples:
0100 -> 0x4 -> dark red
1100 -> 0xC -> bright red
0111 -> 0x7 -> dark white (gray)
1000 -> 0x8 -> bright black (also gray, but slightly darker)
1101 -> 0xD -> bright purple
0001 -> 0x1 -> dark blue
and so on...

If you want a complete list of colors. A good place to find it is to write "help color" in cmd.
Last edited on
Use an API to display images on the screen, preferably SFML: www.sfml-dev.org
You can draw stuff in the Windows Console...

Here's a snippet plotting a sine wave:
http://www.daniweb.com/code/snippet216474.html

LOL.
Topic archived. No new replies allowed.