Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. `#include <iostream>
  2. #include <conio.h>
  3. #include <fstream>
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6. using namespace std;
  7.  
  8.  
  9. unsigned char* editing(char* filename)
  10. {
  11. int i;
  12. int j;
  13. FILE* mybmpfilespointer;
  14. mybmpfilespointer = fopen(filename, "rb");
  15. unsigned char headerinfo[54];
  16. 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 );
  17.  
  18. // extract image height and width from header
  19. int width = *(int*)&headerinfo[18];
  20. int height = *(int*)&headerinfo[22];
  21.  
  22. int size = 3 * width * height;
  23. unsigned char* imagesdata = new unsigned char[size]; // allocate 3 bytes per pixel
  24. fread(imagesdata, sizeof(unsigned char), size, mybmpfilespointer); // read the rest of the imagesdata at once
  25.  
  26. // display image height and width from header
  27. cout << " width:" << width << endl;
  28. cout << " height:" << height << endl;
  29.  
  30. ofstream arrayfile("bmpofstream.bmp"); // File Creation
  31.  
  32. for(int a = 0; a < 53; a++) //bgr to rgb
  33. {
  34. arrayfile << headerinfo[a];
  35. }
  36.  
  37. for(int k=0; k<size; k++)
  38. {
  39. arrayfile<<imagesdata[k]<<endl; //Outputs array to file
  40. }
  41. arrayfile.close();
  42.  
  43. delete[] mybmpfilespointer;
  44. delete[] imagesdata;
  45. fclose(mybmpfilespointer);
  46. return imagesdata;
  47. return headerinfo;
  48.  
  49.  
  50. }
  51.  
  52. int main()
  53. {
  54.  
  55. FILE* mybmpfilespointer = fopen("mybmp.bmp", "rb");
  56. if (mybmpfilespointer)
  57. {
  58.  
  59. editing("mybmp.bmp");
  60. }
  61. else
  62. {
  63. cout << "Cant Read File";
  64. }
  65.  
  66. }`
  67.  
  68. for(j = 0; j < size; j++)
  69. {
  70. imagesdata[j]=imagesdata[j]+50;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement