Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `#include <iostream>
- #include <conio.h>
- #include <fstream>
- #include<stdio.h>
- #include<stdlib.h>
- using namespace std;
- unsigned char* editing(char* filename)
- {
- int i;
- int j;
- FILE* mybmpfilespointer;
- mybmpfilespointer = fopen(filename, "rb");
- unsigned char headerinfo[54];
- fread(headerinfo, sizeof(unsigned char), 54, mybmpfilespointer); // read the 54-byte header size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );
- // extract image height and width from header
- int width = *(int*)&headerinfo[18];
- int height = *(int*)&headerinfo[22];
- int size = 3 * width * height;
- unsigned char* imagesdata = new unsigned char[size]; // allocate 3 bytes per pixel
- fread(imagesdata, sizeof(unsigned char), size, mybmpfilespointer); // read the rest of the imagesdata at once
- // display image height and width from header
- cout << " width:" << width << endl;
- cout << " height:" << height << endl;
- ofstream arrayfile("bmpofstream.bmp"); // File Creation
- for(int a = 0; a < 53; a++) //bgr to rgb
- {
- arrayfile << headerinfo[a];
- }
- for(int k=0; k<size; k++)
- {
- arrayfile<<imagesdata[k]<<endl; //Outputs array to file
- }
- arrayfile.close();
- delete[] mybmpfilespointer;
- delete[] imagesdata;
- fclose(mybmpfilespointer);
- return imagesdata;
- return headerinfo;
- }
- int main()
- {
- FILE* mybmpfilespointer = fopen("mybmp.bmp", "rb");
- if (mybmpfilespointer)
- {
- editing("mybmp.bmp");
- }
- else
- {
- cout << "Cant Read File";
- }
- }`
- for(j = 0; j < size; j++)
- {
- imagesdata[j]=imagesdata[j]+50;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement