Advertisement
Guest User

Untitled

a guest
May 4th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. public static BlockingQueue<ImageSaveData> imageQueue1 = new LinkedBlockingQueue<ImageSaveData>();
  2. public static BlockingQueue<ImageSaveData> imageQueue2 = new LinkedBlockingQueue<ImageSaveData>();
  3. public static BlockingQueue<ImageSaveData> imageQueue3 = new LinkedBlockingQueue<ImageSaveData>();
  4. public static BlockingQueue<ImageSaveData> imageQueue4 = new LinkedBlockingQueue<ImageSaveData>();
  5.  
  6. import java.awt.image.BufferedImage;
  7.  
  8. public class ImageSaveData
  9. {
  10. private String fileNumber;
  11. private BufferedImage image;
  12.  
  13. public ImageSaveData(String fileNumber, BufferedImage image)
  14. {
  15. this.fileNumber = fileNumber;
  16. this.image = image;
  17. }
  18.  
  19. public String getFileNumber()
  20. {
  21. return fileNumber;
  22. }
  23.  
  24. public BufferedImage getImage()
  25. {
  26. return image;
  27. }
  28. }
  29.  
  30. // long start = System.currentTimeMillis();
  31. synchronized (runner)
  32. {
  33. int imageCount = 0;
  34. int maxCount = 0;
  35. boolean hasMessage = false;
  36. String[] countFormat =
  37. {
  38. "00000000", "0000000", "000000", "00000", "0000", "000", "00", "0"
  39. };
  40. // 10
  41. while (true)
  42. {
  43. if (maxCount++ < 1000000010)
  44. {
  45. try
  46. {
  47. BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
  48. String imageOutNumb = "";
  49. if (imageCount < 10) imageOutNumb = countFormat[0] + imageCount++;
  50. else if (imageCount < 100) imageOutNumb = countFormat[1] + imageCount++;
  51. else if (imageCount < 1000) imageOutNumb = countFormat[2] + imageCount++;
  52. else if (imageCount < 10000) imageOutNumb = countFormat[3] + imageCount++;
  53. else if (imageCount < 100000) imageOutNumb = countFormat[4] + imageCount++;
  54. else if (imageCount < 1000000) imageOutNumb = countFormat[5] + imageCount++;
  55. else if (imageCount < 10000000) imageOutNumb = countFormat[6] + imageCount++;
  56. else if (imageCount < 100000000) imageOutNumb = countFormat[7] + imageCount++;
  57. else imageOutNumb = "" + imageCount++;
  58.  
  59. ImageSaveData imageSaveData = new ImageSaveData(imageOutNumb, image);
  60.  
  61. while (true)
  62. {
  63. if (Main.imageQueue1.offer(imageSaveData, 1, TimeUnit.NANOSECONDS)) break;
  64. if (Main.imageQueue2.offer(imageSaveData, 1, TimeUnit.NANOSECONDS)) break;
  65. if (Main.imageQueue3.offer(imageSaveData, 1, TimeUnit.NANOSECONDS)) break;
  66. if (Main.imageQueue4.offer(imageSaveData, 1, TimeUnit.NANOSECONDS)) break;
  67. }
  68. }
  69. catch (HeadlessException | AWTException e)
  70. {
  71. e.printStackTrace();
  72. }
  73. catch (InterruptedException e)
  74. {
  75. e.printStackTrace();
  76. }
  77. catch(OutOfMemoryError e)
  78. {
  79. try
  80. {
  81. runner.sleep(1);
  82. }
  83. catch (InterruptedException e1)
  84. {
  85. // TODO Auto-generated catch block
  86. e1.printStackTrace();
  87. }
  88. }
  89. try
  90. {
  91. runner.sleep(34);
  92. }
  93. catch (InterruptedException e)
  94. {
  95. // TODO Auto-generated catch block
  96. e.printStackTrace();
  97. }
  98. }
  99. else
  100. {
  101. if (hasMessage)
  102. {
  103. try
  104. {
  105. System.out.println(Main.imageQueue1.isEmpty());
  106. System.out.println(Main.imageQueue2.isEmpty());
  107. System.out.println(Main.imageQueue3.isEmpty());
  108. System.out.println(Main.imageQueue4.isEmpty());
  109. }
  110. catch (Exception e)
  111. {
  112.  
  113. }
  114. }
  115. else
  116. {
  117. System.out.println("We Have Finished saving images to memory");
  118. hasMessage = true;
  119. }
  120. }
  121. }
  122. }
  123.  
  124. // long start = System.currentTimeMillis();
  125. synchronized (runner)
  126. {
  127. String PathName = "\\DELL\Maxtor\aJordan\";
  128. while (true)
  129. {
  130. try
  131. {
  132. ImageSaveData imageData1 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
  133. ImageSaveData imageData2 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
  134. ImageSaveData imageData3 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
  135. ImageSaveData imageData4 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
  136. if (imageData1 != null) ImageIO.write(imageData1.getImage(), "png", new File(PathName + imageData1.getFileNumber() + ".png"));
  137. if (imageData2 != null) ImageIO.write(imageData2.getImage(), "png", new File(PathName + imageData2.getFileNumber() + ".png"));
  138. if (imageData3 != null) ImageIO.write(imageData3.getImage(), "png", new File(PathName + imageData3.getFileNumber() + ".png"));
  139. if (imageData4 != null) ImageIO.write(imageData4.getImage(), "png", new File(PathName + imageData4.getFileNumber() + ".png"));
  140.  
  141.  
  142. }
  143. catch (InterruptedException e)
  144. {
  145. // TODO Auto-generated catch block
  146. e.printStackTrace();
  147. }
  148. catch (IOException e)
  149. {
  150. // TODO Auto-generated catch block
  151. e.printStackTrace();
  152. }
  153. }
  154. }
  155.  
  156. java.lang.OutOfMemoryError: Java heap space
  157. at sun.awt.windows.WRobotPeer.getRGBPixels(Unknown Source)
  158. at java.awt.Robot.createScreenCapture(Unknown Source)
  159. at TakeShothandler1.run(TakeShothandler1.java:48)
  160. at java.lang.Thread.run(Unknown Source)
  161.  
  162. BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
  163.  
  164. ImageSaveData imageData1 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
  165. ImageSaveData imageData2 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
  166. ImageSaveData imageData3 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
  167. ImageSaveData imageData4 = Main.imageQueue1.poll(1, TimeUnit.NANOSECONDS);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement