Janilabo

Janilabo | ReplaceColor(s)(Tol)In [SCAR Divi 3.38+]

Jan 26th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.21 KB | None | 0 0
  1. procedure ReplaceColorIn(var bmp: TSCARBitmap; XS, YS, XE, YE: Integer; color, newColor: Integer);
  2. var
  3.   b: TSCARBitmap;
  4.   c: TSCARClient;    
  5. begin
  6.   case ((XS <= XE) and (YS <= YE) and InRange(XS, 0, (bmp.Width - 1)) and InRange(XE, 0, (bmp.Width - 1)) and InRange(YS, 0, (bmp.Height -1)) and InRange(YE, 0, (bmp.Height -1))) of
  7.     True:
  8.     try
  9.       c := SetClient(TSCARBitmapClient.Create(bmp));
  10.       try
  11.         b := GetClient.CaptureEx(XS, YS, XE, YE);  
  12.         try
  13.           ReplaceColor(b, color, newColor);  
  14.           b.DrawTo(bmp, XS, YS);
  15.         except
  16.         finally
  17.           b.Free;
  18.         end;
  19.       except
  20.       finally
  21.         SetClient(c).Free;
  22.       end;
  23.     except    
  24.     end;
  25.     False: RaiseException(erException, 'Invalid area!');
  26.   end;
  27. end;
  28.  
  29. procedure ReplaceColorTolIn(var bmp: TSCARBitmap; XS, YS, XE, YE: Integer; color, newColor, tol: Integer);
  30. var
  31.   b: TSCARBitmap;
  32.   c: TSCARClient;    
  33. begin
  34.   case ((XS <= XE) and (YS <= YE) and InRange(XS, 0, (bmp.Width - 1)) and InRange(XE, 0, (bmp.Width - 1)) and InRange(YS, 0, (bmp.Height -1)) and InRange(YE, 0, (bmp.Height -1))) of
  35.     True:
  36.     try
  37.       c := SetClient(TSCARBitmapClient.Create(bmp));
  38.       try
  39.         b := GetClient.CaptureEx(XS, YS, XE, YE);  
  40.         try
  41.           ReplaceColorTol(b, color, newColor, tol);  
  42.           b.DrawTo(bmp, XS, YS);
  43.         except
  44.         finally
  45.           b.Free;
  46.         end;
  47.       except
  48.       finally
  49.         SetClient(c).Free;
  50.       end;
  51.     except    
  52.     end;
  53.     False: RaiseException(erException, 'Invalid area!');
  54.   end;
  55. end;
  56.  
  57. procedure ReplaceColorsIn(var bmp: TSCARBitmap; XS, YS, XE, YE: Integer; colors: TIntArray; newColor: Integer);
  58. var
  59.   b: TSCARBitmap;
  60.   c: TSCARClient;    
  61. begin
  62.   case ((XS <= XE) and (YS <= YE) and InRange(XS, 0, (bmp.Width - 1)) and InRange(XE, 0, (bmp.Width - 1)) and InRange(YS, 0, (bmp.Height -1)) and InRange(YE, 0, (bmp.Height -1))) of
  63.     True:
  64.     try
  65.       c := SetClient(TSCARBitmapClient.Create(bmp));
  66.       try
  67.         b := GetClient.CaptureEx(XS, YS, XE, YE);  
  68.         try
  69.           ReplaceColors(b, colors, newColor);  
  70.           b.DrawTo(bmp, XS, YS);
  71.         except
  72.         finally
  73.           b.Free;
  74.         end;
  75.       except
  76.       finally
  77.         SetClient(c).Free;
  78.       end;
  79.     except    
  80.     end;
  81.     False: RaiseException(erException, 'Invalid area!');
  82.   end;
  83. end;
  84.  
  85. procedure ReplaceColorsTolIn(var bmp: TSCARBitmap; XS, YS, XE, YE: Integer; colors: TIntArray; newColor, tol: Integer);
  86. var
  87.   b: TSCARBitmap;
  88.   c: TSCARClient;    
  89. begin
  90.   case ((XS <= XE) and (YS <= YE) and InRange(XS, 0, (bmp.Width - 1)) and InRange(XE, 0, (bmp.Width - 1)) and InRange(YS, 0, (bmp.Height -1)) and InRange(YE, 0, (bmp.Height -1))) of
  91.     True:
  92.     try
  93.       c := SetClient(TSCARBitmapClient.Create(bmp));
  94.       try
  95.         b := GetClient.CaptureEx(XS, YS, XE, YE);  
  96.         try
  97.           ReplaceColorsTol(b, colors, newColor, tol);  
  98.           b.DrawTo(bmp, XS, YS);
  99.         except
  100.         finally
  101.           b.Free;
  102.         end;
  103.       except
  104.       finally
  105.         SetClient(c).Free;
  106.       end;
  107.     except    
  108.     end;
  109.     False: RaiseException(erException, 'Invalid area!');
  110.   end;
  111. end;
Advertisement
Add Comment
Please, Sign In to add comment