Advertisement
prjbrook

BMPDots3.cpp

Jan 23rd, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. /*************************************************
  2. * *
  3. * EasyBMP Cross-Platform Windows Bitmap Library *
  4. * *
  5. * Author: Paul Macklin *
  6. * email: macklin01@users.sourceforge.net *
  7. * support: http://easybmp.sourceforge.net *
  8. * *
  9. * file: EasyBMPsample.cpp *
  10. * date added: 03-31-2006 *
  11. * date modified: 12-01-2006 *
  12. * version: 1.06 *
  13. * *
  14. * License: BSD (revised/modified) *
  15. * Copyright: 2005-6 by the EasyBMP Project *
  16. * *
  17. * description: Sample application to demonstrate *dir
  18. * some functions and capabilities *
  19. * *
  20. *************************************************/
  21. //To do: Create file of 1,3,7,9 from rand(). Read file in a place relevant dot on BMP.
  22.  
  23. #include "EasyBMP.h"
  24. #include<stdlib.h>
  25. #include<conio.h>
  26. using namespace std;
  27.  
  28. int main( int argc, char* argv[] )
  29. {
  30. cout << endl
  31. << "Using EasyBMP Version " << _EasyBMP_Version_ << endl << endl
  32. << "Copyright (c) by the EasyBMP Project 2005-6" << endl
  33. << "WWW: http://easybmp.sourceforge.net" << endl << endl;
  34.  
  35. BMP Text;
  36. Text.ReadFromFile("box0.bmp");
  37. // Text.ReadFromFile("EasyBMPtext.bmp");
  38. BMP Background;
  39. Background.ReadFromFile("Threes.bmp");
  40. // Background.ReadFromFile("EasyBMPbackground.bmp");
  41.  
  42. BMP AnImage;
  43. AnImage.SetSize(640,480);
  44. AnImage.SetBitDepth(8);
  45. //AnImage.ReadFromFile("sample.bmp");
  46. cout << "File info:" << endl;
  47. cout << AnImage.TellWidth() << " x " << AnImage.TellHeight() << " at " << AnImage.TellBitDepth() << " bpp" << endl;
  48. cout << "colors: " << AnImage.TellNumberOfColors() << endl;
  49. cout << "(" << (int) AnImage(14,18)->Red << "," << (int) AnImage(14,18)->Green << "," << (int) AnImage(14,18)->Blue << "," << (int) AnImage(14,18)->Alpha << ")" << endl;
  50.  
  51.  
  52. //cout<<rand()<<"\t";
  53. int randDigit,i,j,ones,threes,sevens,nines;
  54. long nonPrimes=0;
  55. j=0; ones=threes=sevens=nines=0;
  56.  
  57. while (j<480)
  58. {
  59. randDigit = rand()%10;
  60. //cout<<rand()%10<<"\t";
  61. //cout<<randDigit<<"\t";
  62. switch (randDigit)
  63. {
  64. case 1:
  65. AnImage(i,j)->Red = 255;
  66. AnImage(i,j)->Green = 255;
  67. AnImage(i,j)->Blue = 0;
  68. ones++;
  69. break;
  70. case 3:
  71. AnImage(i,j)->Red = 255;
  72. AnImage(i,j)->Green = 0;
  73. AnImage(i,j)->Blue = 0;
  74. threes++;
  75. break;
  76. case 7:
  77. AnImage(i,j)->Red = 0;
  78. AnImage(i,j)->Green = 255;
  79. AnImage(i,j)->Blue = 0;
  80. sevens++;
  81. break;
  82. case 9:
  83. //cout << "Got a nine" << endl;
  84. AnImage(i,j)->Red = 0;
  85. AnImage(i,j)->Green = 0;
  86. AnImage(i,j)->Blue = 255;
  87. nines++;
  88. break;
  89. default:
  90. //cout << "Not1,2" << endl;
  91. nonPrimes++;
  92. i--;
  93. }
  94. i++;
  95. if (i==640) {
  96. i=0;
  97. j++;
  98. }
  99. }
  100. AnImage.WriteToFile("copied1dots2.bmp");
  101. cout << "Non primes= " << nonPrimes << endl;
  102. cout << "Ones =" << ones;
  103. cout << " Threes =" << threes;
  104. cout << " Sevens =" << sevens;
  105. cout << " Nines =" << nines << endl;
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement