This may seem like a newbish question (because it is) but can anyone point me in the right direction as to where I can find information on writing .bmp files? All I want to do is give the program a random number seed, and it generates a noise map from this seed. Sounds simply enough, but I don't know where to begin on actually writing the color values. I realize that bmp's color data is in BRG format and I should probably have this data stored in an array of BYTE's, but thats about all I know. Any help would be appreciated, I don't even need any code really, just some guidance (I'd actually prefer guidance over code, I learn more than way :) ).
Thanks!
7 9616
What language are you implementing this in?
This may seem like a newbish question (because it is) but can anyone point me in the right direction as to where I can find information on writing .bmp files? All I want to do is give the program a random number seed, and it generates a noise map from this seed. Sounds simply enough, but I don't know where to begin on actually writing the color values. I realize that bmp's color data is in BRG format and I should probably have this data stored in an array of BYTE's, but thats about all I know. Any help would be appreciated, I don't even need any code really, just some guidance (I'd actually prefer guidance over code, I learn more than way :) ).
Thanks!
Do you know how to read in a BMP?
Sorry. C++. I sort of understand how to read a bmp, and I know they are stored upside down (but that won't matter for this program, I am just generating noise). After I fill my file information (BITMAPFILEHEADER and BITMAPINFOHEADER) and fill my array with my RGB and bitcount information, how do I save it to the BMP format I guess is my question? Here is the only information I have already found on reading BMP's, so this is what I have been working off of:
::Link removed::
Thanks for the replies!
Sorry. C++. I sort of understand how to read a bmp, and I know they are stored upside down (but that won't matter for this program, I am just generating noise). After I fill my file information (BITMAPFILEHEADER and BITMAPINFOHEADER) and fill my array with my RGB and bitcount information, how do I save it to the BMP format I guess is my question? Here is the only information I have already found on reading BMP's, so this is what I have been working off of:
::Link removed::
Thanks for the replies!
It's only the matter of changing the ReadFile() function with WriteFile() one.
So everything is the same.
You:
1.Initialize bitmap file header and write it to the newly created file,
2.Initialize bitmap info header and write it to the file,
3.Create any data you want,
4.Once finished write it to the file,
5.Close the file.
That should be it.
It's only the matter of changing the ReadFile() function with WriteFile() one.
So everything is the same.
You:
1.Initialize bitmap file header and write it to the newly created file,
2.Initialize bitmap info header and write it to the file,
3.Create any data you want,
4.Once finished write it to the file,
5.Close the file.
That should be it.
Thanks, I figured it was something simple, but I have never really used image files before (besides in GUI). I'll whip something up and post it if it works. Thanks again!
Thanks, I figured it was something simple, but I have never really used image files before (besides in GUI). I'll whip something up and post it if it works. Thanks again!
Ok, I'm stuck now. What's the difference between RGBTRIPLE and RGBQUAD? I have been looking through the MSDN documentation and they don't have any usage examples for either of these structs like they normally do.
Here is what I have so far: - HANDLE file;
-
BITMAPFILEHEADER fileHeader;
-
BITMAPINFOHEADER fileInfo;
-
RGBTRIPLE *image;
-
image = new RGBTRIPLE[512*512];
-
-
file = CreateFile("example.bmp",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_NEW,NULL,NULL); //Sets up the new bmp to be written to
-
-
fileHeader.bfType = 'BM'; //Sets our type to BM or bmp
-
fileHeader.bfSize = sizeof(BITMAPFILEHEADER); //Sets the size equal to the size of the header struct
-
fileHeader.bfReserved1 = 0; //sets the reserves to 0
-
fileHeader.bfReserved2 = 0;
-
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); //Sets offbits equal to the size of file and info header (should be 24 bits per pixel)
-
-
fileInfo.biSize = sizeof(BITMAPINFOHEADER);
-
fileInfo.biWidth = 512;
-
fileInfo.biHeight = 512;
-
fileInfo.biPlanes = 1;
-
fileInfo.biBitCount = 24;
-
fileInfo.biCompression = BI_RGB;
-
fileInfo.biSizeImage = 0;
-
fileInfo.biXPelsPerMeter = 2400;
-
fileInfo.biYPelsPerMeter = 2400;
-
-
WriteFile(file,&fileHeader,sizeof(fileHeader),NULL,NULL);
-
WriteFile(file,&fileInfo,sizeof(fileInfo),NULL,NULL);
-
Nevermind, I finally got it! Thanks for the help guys! Heres the code (this isn't school work): -
#include "stdafx.h"
-
#include <iostream>
-
#include <fstream>
-
#include <windows.h>
-
-
using namespace std;
-
-
-
int main()
-
{
-
HANDLE file;
-
BITMAPFILEHEADER fileHeader;
-
BITMAPINFOHEADER fileInfo;
-
RGBTRIPLE *image;
-
DWORD write = 0;
-
image = new RGBTRIPLE[512*512*24];
-
-
file = CreateFile("example.bmp",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); //Sets up the new bmp to be written to
-
-
fileHeader.bfType = 19778; //Sets our type to BM or bmp
-
fileHeader.bfSize = sizeof(fileHeader.bfOffBits) + sizeof(RGBTRIPLE); //Sets the size equal to the size of the header struct
-
fileHeader.bfReserved1 = 0; //sets the reserves to 0
-
fileHeader.bfReserved2 = 0;
-
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); //Sets offbits equal to the size of file and info header
-
-
fileInfo.biSize = sizeof(BITMAPINFOHEADER);
-
fileInfo.biWidth = 512;
-
fileInfo.biHeight = 512;
-
fileInfo.biPlanes = 1;
-
fileInfo.biBitCount = 24;
-
fileInfo.biCompression = BI_RGB;
-
fileInfo.biSizeImage = 512 * 512 * (24/8);
-
fileInfo.biXPelsPerMeter = 2400;
-
fileInfo.biYPelsPerMeter = 2400;
-
fileInfo.biClrImportant = 0;
-
fileInfo.biClrUsed = 0;
-
-
WriteFile(file,&fileHeader,sizeof(fileHeader),&write,NULL);
-
WriteFile(file,&fileInfo,sizeof(fileInfo),&write,NULL);
-
-
for (int i = 0; i < 512*512*24; i++)
-
{
-
image[i].rgbtBlue = 255;
-
image[i].rgbtGreen = 0;
-
image[i].rgbtRed = 0;
-
}
-
-
WriteFile(file, image, fileInfo.biSizeImage, &write, NULL);
-
-
CloseHandle(file);
-
-
}
-
-
It doesn't do what I want yet, but thats an easy fix. This just creates an all blue bmp.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joseph |
last post by:
Hi
I'm writing a commercial program which must be reliable. It has to do
some basic reading and writing to and from files on the hard disk,
and also to a floppy.
I have foreseen a potential...
|
by: Sebastian Kemi |
last post by:
How should a write a class to a file?
Would this example work:
object *myobject = 0;
tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object));
/ sebek
|
by: ishekar |
last post by:
Hi,
I have an application where i want to write data to a file, the data is
being sent from an external source. I know the total size of the data and
then i retrieve the data in small segments...
|
by: Daniel |
last post by:
System.IO.StreamWriter Close or Flush method to shut down the computer in
such a way that just part of the file is written? or an empty file is
written? Also if the Close or Flush is to a...
|
by: Jeong-Gun Lee |
last post by:
I'm writing a code of writing a value to a specific memory address.
=================================================================
#include <stdio.h>
int main()
{
long air;
long...
|
by: Xah Lee |
last post by:
i had the pleasure to read the PHP's manual today.
http://www.php.net/manual/en/
although Pretty Home Page is another criminal hack of the unix lineage,
but if we are here to judge the quality...
|
by: Claudio Grondi |
last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want
to change only eight bytes in this file at a given offset of appr. 200
Gbyte (all other data in that file should remain...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: Barry Flynn |
last post by:
Hi
I am working with a VB 2005 program which has been converted from VB6.
It writes data out to a flat file, with code like the following line
WriteLine(riFileNo, "Hist", lsAssetID,...
|
by: Skybuck Flying |
last post by:
Hello,
This morning I had an idea how to write Scalable Software in general.
Unfortunately with Delphi 2007 it can't be done because it does not support
operating overloading for classes, or...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |