Advertisement
Guest User

Untitled

a guest
May 24th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public static void Main(string[] args)
  2. {
  3. Stopwatch s = new Stopwatch();
  4. s.Start();
  5.  
  6. while(true) {
  7. long start = s.ElapsedMilliseconds;
  8.  
  9. Bitmap b = new Bitmap(1280, 720);
  10.  
  11. BitmapData bData = b.LockBits(
  12. new Rectangle(Point.Empty, b.Size),
  13. ImageLockMode.ReadWrite,
  14. PixelFormat.Format24bppRgb);
  15.  
  16. int numBytes = Math.Abs(bData.Stride) * b.Height;
  17.  
  18. byte[] rgbValues = new byte[numBytes];
  19.  
  20. for(int i = 2; i < numBytes - 2; i += 3) {
  21. if(0.3 * rgbValues[i] + 0.3 * rgbValues[i + 1] + 0.4 * rgbValues[i + 2] < 0.4) {
  22. rgbValues[i] = 255;
  23. rgbValues[i + 1] = 0;
  24. rgbValues[i + 2] = 0;
  25. }
  26. }
  27.  
  28. System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, bData.Scan0, numBytes);
  29.  
  30. b.UnlockBits(bData);
  31.  
  32. b.Save("huy.png");
  33.  
  34. Console.WriteLine("{0:F3}", (s.ElapsedMilliseconds - start) / 1000.0);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement