Hello.I am just starting to use c++ and I have already some difficulties.I am working with intel c++ compiler 7.I would like to load a bmp image on a matrix.I only can open and read its BITMAPINFOHEADER.How can I load values opend image on a matrix?This is what I have produced" -
#include <stdio.h>
-
#include <math.h>
-
#include <conio.h>
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <windows.h>
-
-
#define WIDTHBYTES(bits) ((((bits) + 31) >> 5) << 2)
-
-
void load_bitmap(char *,int,int,void *);
-
-
void main(int argc, char *argv[])
-
{
-
int i=0,j=0;
-
int w=0,h=0,z=0,t=0;
-
int altezza,profondita;
-
void *buf;
-
char *name = "polyhedron8.bmp";
-
// FILE *in;
-
-
// in=fopen("C:\Program Files\Microsoft Visual Studio\VC98\Include\polyhedron2","r");
-
-
// name = in;
-
// printf("il valore in cui e memorizzata l`immagine vale %d \n",in);
-
printf("koko de\n");
-
load_bitmap(name,w,h,&buf);
-
printf("oaru\n");
-
-
}
-
-
-
void load_bitmap(char* filename,int width, int height, void* buffer)
-
{
-
BITMAPFILEHEADER bfh;
-
BITMAPINFOHEADER bih;
-
FILE* fp;
-
int widthbytes = WIDTHBYTES(width * 24);
-
int i=0,z=0,t=0;
-
int tot=0;
-
-
-
if((fp = fopen(filename, "rb")) == NULL)
-
{
-
printf("Cannot open");
-
return;
-
}
-
fread(&bfh,sizeof(BITMAPFILEHEADER), 1, fp);
-
fread(&bih,sizeof(BITMAPINFOHEADER), 1, fp);
-
-
fread(buffer, sizeof(BYTE), widthbytes * height, fp);
-
-
}
-
is there anyone who can help me?
1 3226 Savage 1,764
Recognized Expert Top Contributor
Hello.I am just starting to use c++ and I have already some difficulties.I am working with intel c++ compiler 7.I would like to load a bmp image on a matrix.I only can open and read its BITMAPINFOHEADER.How can I load values opend image on a matrix?This is what I have produced" -
#include <stdio.h>
-
#include <math.h>
-
#include <conio.h>
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <windows.h>
-
-
#define WIDTHBYTES(bits) ((((bits) + 31) >> 5) << 2)
-
-
void load_bitmap(char *,int,int,void *);
-
-
void main(int argc, char *argv[])
-
{
-
int i=0,j=0;
-
int w=0,h=0,z=0,t=0;
-
int altezza,profondita;
-
void *buf;
-
char *name = "polyhedron8.bmp";
-
// FILE *in;
-
-
// in=fopen("C:\Program Files\Microsoft Visual Studio\VC98\Include\polyhedron2","r");
-
-
// name = in;
-
// printf("il valore in cui e memorizzata l`immagine vale %d \n",in);
-
printf("koko de\n");
-
load_bitmap(name,w,h,&buf);
-
printf("oaru\n");
-
-
}
-
-
-
void load_bitmap(char* filename,int width, int height, void* buffer)
-
{
-
BITMAPFILEHEADER bfh;
-
BITMAPINFOHEADER bih;
-
FILE* fp;
-
int widthbytes = WIDTHBYTES(width * 24);
-
int i=0,z=0,t=0;
-
int tot=0;
-
-
-
if((fp = fopen(filename, "rb")) == NULL)
-
{
-
printf("Cannot open");
-
return;
-
}
-
fread(&bfh,sizeof(BITMAPFILEHEADER), 1, fp);
-
fread(&bih,sizeof(BITMAPINFOHEADER), 1, fp);
-
-
fread(buffer, sizeof(BYTE), widthbytes * height, fp);
-
-
}
-
is there anyone who can help me?
You said that you are using C++,right?
Then why don't you use file streams?
Now to the real problem,you are not reading those valuse yet.You need to skip few bytes to read width,height...
Take a look at this pseudo-code: - If open Bitmap file
-
Read two bytes (type) and if different than 0x4D42 stop
-
Ignore eight bytes
-
Read four bytes (start of image data)
-
Ignore four bytes
-
Read four bytes (width of bitmap)
-
Read four bytes (height of bitmap)
-
Ignore two bytes
-
Read two bytes (bit count of bitmap) and if different than 24 stop
-
Read four bytes (compression of bitmap) and if different than BI_RGB stop
-
Move to start of image data
-
Allocate memory for image data (3(one byte for red, other for
-
green other for blue) * ImageWidth * ImageHeight)
-
Read (3 * ImageWidth * ImageHeight) bytes from file to buffer
-
Swap the red and blue components of buffer
-
If ImageHeight is negative
-
Flip the buffer lines
-
End if
-
Close file
Note:This is for reading uncompressed bitmaps only!
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ben Ingram |
last post by:
Hi all,
I am writing a template matrix class in which the template parameters are
the number of rows and number of columns. There are a number of reasons
why this is an appropriate tradeoff for...
|
by: Jason |
last post by:
Hello. I am trying to learn how operator overloading works so I wrote
a simple class to help me practice. I understand the basic opertoar
overload like + - / *, but when I try to overload more...
|
by: Harry |
last post by:
Hello,
I am using a 2-dimensional matrix for image manipulation and recognition.
The x-axes is image.width pixels long and the y-axes image.height.
All fields have a RGB integer value.
To store...
|
by: Wayne Shu |
last post by:
Hi everyone:
I'm looking forward to a wonderful matrix class library!
Does someone like to introduce a to me?
It should satisfy the following demands:
1. Open Source.
2. Efficient.
3. Support...
|
by: DarrenWeber |
last post by:
Below is a module (matrix.py) with a class to implement some basic
matrix operations on a 2D list. Some things puzzle me about the best
way to do this (please don't refer to scipy, numpy and...
| |
by: kin560703 |
last post by:
Hello. I have some difficulties.I would like to load a bmp image on a matrix.I don't know how to open and read the black white bmp image and then output the values . For example: supose the *.bmp...
|
by: Marco Biagioni |
last post by:
After i've tried to update a vb 6.0 project to vb.net, using visual studio
utility,i can't read correctly data bytes from a .bmp file to insert them in
a matrix to operate on.
Using vb 6.0 the...
|
by: Marco Biagioni |
last post by:
After i've tried to update a vb 6.0 project to vb.net, using visual studio
utility,i can't read correctly data bytes from a .bmp file to insert them in
a matrix to operate on.
Using vb 6.0 the...
|
by: ProtossLee |
last post by:
Hi,
I am currently working on a project for image processing.
a double matrix m1(1300X1000) need to be converted into bitmap and
displayed on screen.
so far I've made the following code:
For i...
|
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,...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |