Thread: C program for text to image

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    3

    Red face C program for text to image

    Hi im karthikeyan from National Univ of Sing,

    can any one tel the progrm of how to read a text file which has 64x64 characters and to display that as an image, i have copied the contents of the file below.

    actually all the zero should be black so that it forms the back ground, and all the characters from 1-9 and A-V should be assigned an intensity level, from 1-31 in the 32 bit level.

    The image should be white center part and black background showing ABC and 123.



    the text is,



    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00004200000000
    000000000BJH0000000000000000MURRRSLS00000000000000 0COJJKLL000000
    000000004LLK5000000000000000KNNOPONKO0000000000000 HJNHDEJKJ00000
    00000000CMMLJ000000000000000MOD4579MMF00000000000B KL40004FJC0000
    00000002LMILM400000000000000LMS0000EMJ00000000000J M7000003C90000
    00000005MJ4OMO00000000000001MO40000CMF00000000005K K0000000000000
    0000000BMB07NM00000000000002LNA00003NM3000000000DK H0000000000000
    0000000JL301KN20000000000001MOMPROLM300000000000CL O0000000000000
    0000002JJ000FMB0000000000002NOMHHIMNP00000000000BK O0000000000000
    0000004MJ000OMO0000000000002MO40000CNM0000000000SL K0000000000000
    000000DNOUUUMML0000000000003ON300000MN10000000001K M4000000LN0000
    000001KLHOFFFMMD000000000003LO500001MN20000000000F LK00000BJH0000
    000007LI00000FML000000000000MO70000MOL000000000002 LLM500JMK50000
    00000DMD000004JK000000000000NPPTVUONPA000000000000 3KNJJJKMA00000
    00000CE3000000A8000000000000JNNNLNMLO4000000000000 09OIOB00000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    0000000004MJ0000000000000000002STRRD00000000000000 000NNLM9000000
    000000004LMH000000000000000005OMPPOMO0000000000000 08JKHOJJD00000
    000000BONMMI00000000000000000KOE00DNM8000000000000 0IJ6003CI10000
    0000007FOKMH00000000000000000NL0000HMD000000000000 4KE0000BJ50000
    0000000009MI00000000000000000BA0000FME000000000000 0000000EJ30000
    0000000008MH00000000000000000000000KNA000000000000 000000FJ900000
    0000000008MI0000000000000000000000JMK1000000000000 00007JJH000000
    0000000008MI000000000000000000000LNL40000000000000 000004CIJ40000
    0000000008MH00000000000000000000MOI300000000000000 00000007OF0000
    0000000006MH0000000000000000000LOD0000000000000000 05000001OH0000
    0000000007MH000000000000000000JMB00000000000000000 DJB00005HO0000
    0000000007MH00000000000000000AMMJADFID000000000000 3IK4003OID0000
    00000000061D00000000000000000JPOOOOONK000000000000 0AKJJIIJF10000
    00000000001000000000000000000BAAAABA74000000000000 005EHOE7000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000
    00000000000000000000000000000000000000000000000000 00000000000000

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And you have a problem solving which part of the task? We don't "do" other peoples homework on this site - we will help you solve the problem, but you need to do SOME of the work yourself.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    3
    actually im new to C, i dont know how to input the text file, im not asking for full solution, but
    is there any chance to input the data nd get the image.
    because i started the process withh matlab,
    my friends told that we can solve this in C much simpler

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    3
    Quote Originally Posted by matsp View Post
    And you have a problem solving which part of the task? We don't "do" other peoples homework on this site - we will help you solve the problem, but you need to do SOME of the work yourself.

    --
    Mats
    actually im new to C, i dont know how to input the text file, im not asking for full solution, but
    is there any chance to input the data nd get the image.
    because i started the process withh matlab,
    my friends told that we can solve this in C much simpler

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    A C program can open and read the text file.... and then eventually call some supplied graphics function to display pixels. Then you're into Windows calls which aren't technically a C programming problem. Alternatively you could construct a GIF file as your target. Also not really an issue that these forums address. You need to find out what tools are available.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You open a file with fopen.
    You read a file with, well, with a lot of things. fgets, fscanf, fread....
    You close a file with fclose.

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Unless you have to produce an image file, like a bitmap or a pixmap, you could use curses or ncurses...ncurses at least will let you set color intesities on a scale of 1000.

    But that's probably not the answer you really want/need. If this is really an assignment, surely there is some particular method you have been asked to use?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    If i was you I would get an API such as SDL, which will let you set up a window and display graphics.

    Setup a screen buffer with the dimensions set to you files COL/ROW size, then run though each character and each pixel together setting the pixel value based on the character value. Then flip the image into view and delay for a few seconds so you can see it before quitting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  3. HotSpot image controls (web)
    By novacain in forum C# Programming
    Replies: 0
    Last Post: 06-25-2008, 04:27 AM
  4. which data type in image program?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 06-14-2008, 04:17 PM
  5. Replies: 6
    Last Post: 03-03-2005, 03:52 AM