473,322 Members | 1,526 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,322 software developers and data experts.

need some help for constructing a .bmp file

5
hi!
I am working with bmp files for my project.I am having the pixel data (binary.. i.e;10001001001..)and i need to represent it as a .bmp file.I need to construct an image(.bmp) from this data using "C".can anybody tell me how to represent it as a .bmp file?I could read data from an existing .bmp file...but couldnt construct that type of file...I tried to add header to the data directly..but the constructed image is not the one which should be for the given data.should the input data be given in any other format..?ascii..?or any thing?cant we directly read the binary data from a text file as character and write it in a .bmp file after adding header?
hope somebody understands my problem and kindly gives me a reply...
thanks in advance!!
Feb 3 '07 #1
8 2544
Banfa
9,065 Expert Mod 8TB
Are you saysing you want to read a text file an use the data to create an image (bitmap) of the text contained in it?

To do this you will need a font definition to got from text to the image of the letters, i.e. an 'A' value 65 has a given pixel layout and you will need a way to look this up.

Then you will need to write the header and the pixel data to a file.
Feb 5 '07 #2
mvkml
5
thank u..for giving me a reply..
yes i need to represent data in a text file as a .bmp image....
are u saying that we need to give the data as ASCII values..?OR should we give in some other format?PLEASE give me a suggestion..
Feb 5 '07 #3
Banfa
9,065 Expert Mod 8TB
No you will read the data as ASCII values from the text file, you will need to use some sort of font definition to look up the ASCII value and then work out how to draw it on a bitmap. Having worked out what colour each pixel in the bitmap should be you can then save it.
Feb 5 '07 #4
macklin01
145 100+
Once you write the file headers of the image, you could overwrite the pixel data with the text. On a standard, 24 bit per pixel image, red, green, and blue are 1 byte each, i.e., 3 characters.

If you decide to use C++ instead of C, you can use my open source / cross-platform EasyBMP C++ bitmap library. Using that, it's very easy.

Expand|Select|Wrap|Line Numbers
  1. #include "EasyBMP.h" 
  2.  
  3. // ... 
  4.  
  5. // assume that you have an array of N characters in a char array.
  6.  
  7. // decide an appropriate image size. it must meet or exceed 
  8. // the data size.
  9.  
  10. BMP Output;
  11.  
  12. int NumberOfPixels = N / 3;
  13. if( 3*NumberOfPixels < N )
  14. { NumerOfPixels++; }
  15.  
  16. int Width = (int) sqrt( NumerOfPixels ); 
  17. int Height = NumerOfPixels / Width;
  18. while( Width*Height < NumerOfPixels )
  19. { Height++; }
  20.  
  21. Output.SetSize( Width, Height );
  22.  
  23. // scroll through the image and place each character
  24.  
  25. int i=0; 
  26. int j=0; 
  27. int n = 0;
  28. while( n < N )
  29. {
  30.  Output(i,j)->Red = (ebmpBYTE) text[n];
  31.  n++;
  32.  i++; 
  33.  if( i >= Output.TellWidth() )
  34.  { j++; i=0; }
  35.  
  36.  if( n < N )
  37.  { Output(i,j)->Green = (ebmpBYTE) text[n]; }
  38.  n++;
  39.  i++; 
  40.  if( i >= Output.TellWidth() )
  41.  { j++; i=0; }
  42.  
  43.  if( n < N )
  44.  { Output(i,j)->Blue = (ebmpBYTE) text[n]; }
  45.  n++;
  46.  i++; 
  47.  if( i >= Output.TellWidth() )
  48.  { j++; i=0; }
  49. }
  50.  
  51. Output.WriteToFile("blah.bmp" );
  52.  
-- Paul
Feb 7 '07 #5
mvkml
5
thank you banfa and macklin..for your suggestions..
i wil try in these lines...
Feb 9 '07 #6
mvkml
5
[to macklin] thank u for u r source code...but i dont know c++..so i need to do it with c only..wil it not be possible with c?
[to banfa] can u tell me what is that font defintion u hav asked me to look up for the ascii?i couldnt understand...
Feb 9 '07 #7
Banfa
9,065 Expert Mod 8TB
[to banfa] can u tell me what is that font defintion u hav asked me to look up for the ascii?i couldnt understand...
No you need to create a font definition and then when you read a character using it to put the right pixels into the bitmap.

Typically a simply font definition consists of a 2 dimensional array of bits in rows and colums for each character in the font where a bit is 1 where the foreground colour must be used and 0 where the background colour must be used.

There is anouther way to do this, uou can

Create a bitmap in memory
Create a device context(DC) for the bitmap
Load the text from the file
Use Windows API calls to draw the text in any loaded font in windows onto the bitmap
Save the bitmap as a BMP file.
Destroy the DC
Destroy the memory bitmap
Feb 9 '07 #8
mvkml
5
thank u very much..
i read the ascii values of da data from text file ...and added header..as you told before..now i could get da correct bmp.so i think i need not try da last method u hav said as i could get the bmp img with u r 2nd reply itself...thank u very much..for suuggesting me to read data as ascii...
Feb 9 '07 #9

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

Similar topics

9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
5
by: bjorgenson | last post by:
Here is my dilema: I want a form that includes an input box and submit button. A user will type in some data in the input box. When they click submit, I need set variables appended to this input...
7
by: Naren | last post by:
Hello All, Can any one help me in this file read problem. #include <stdio.h> int main() {
4
by: technocrat | last post by:
I am trying to update a million rows in a table and doing this reading from a file which has the record pkids and constructing a preparedstatemtn with that pkid and adding it to the batch......
3
by: kurrent | last post by:
i'm still new to php and programming and was hoping to get some help on a few questions i haven't had success in answering myself. I successfully created my first very simple script to accomplish a...
4
by: mcyi2mr3 | last post by:
hi i have a table like this: product id | product name | product price the product name and product price fields both contain duplicate values for example:
7
by: elgiei | last post by:
Good morning at all, i have to implement a server,that every n-seconds (eg. 10sec) sends to other clients,which files and directory has been deleted or modified. i build a n-tree, for each...
2
by: Abe amer | last post by:
Dear All I'm a phd student. and I'm doing now a medicine research. I need your help in : if I want to have a visual basic 2005 table (for example an Access table) that is connected to a program....
4
by: CK | last post by:
Good Morning All, Can use use a variable for the FOR clause in a cursor? Example I have DECLARE @a varchar(50), @b varchar(50), @c varchar(50) DECLARE @sql varchar(255) DECLARE @x...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.