程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 創建RGB、CMYK顏色分量圓代碼

創建RGB、CMYK顏色分量圓代碼

編輯:Delphi

 創建RGB分量圓:

function CreateRGBCircles(const size: INTEGER;
   const Rflag, Gflag, Bflag: BOOLEAN): TBitmap;
var
   AdjustedSize: INTEGER;
   Border: INTEGER;
   i, iR, iG, iB: INTEGER;
   j, jR, jG, jB: INTEGER;
   jOffset: INTEGER;
   RadiusSquared: INTEGER;
   row: pRGBTripleArray;

   function DistanceSquared(const x1, y1, x2, y2: INTEGER): INTEGER;
   begin
      RESULT := SQR(x1 - x2) + SQR(y1 - y2)
   end {兩點間距平方};

begin
   Border := MulDiv(size, 5, 1000);

   AdjustedSize := size - 2 * Border;

   RadiusSquared := SQR(MulDiv(AdjustedSize, 2, 6));

   iR := Border + MulDiv(AdjustedSize, 2, 6);
   iG := Border + MulDiv(AdjustedSize, 3, 6);
   iB := Border + MulDiv(AdjustedSize, 4, 6);
   //RGB顏色圈內的橫坐標
   jOffset := ROUND(AdjustedSize * (2 - SQRT(3)) / 12);
   jR := jOffset + Border + Round(AdjustedSize * (2 + SQRT(3)) / 6);
   jG := jOffset + Border + MulDiv(AdjustedSize, 2, 6);
   jB := jR;
   //RGB顏色圈內的縱坐標
   RESULT := TBitmap.Create;
   //輸出位圖
   RESULT.Width := size;
   RESULT.Height := size;
   RESULT.PixelFormat := pf24bit;
   RESULT.Canvas.Brush.Color := RGB(0, 0, 0);
   // 黑色背景
   RESULT.Canvas.FillRect(RESULT.Canvas.ClipRect);
   //填充
   for j := 0 to RESULT.Height - 1 do
      begin
         row := RESULT.Scanline[j];
         for i := 0 to RESULT.Width - 1 do
            begin
               with row[i] do
                  begin
                     if Rflag and (DistanceSquared(i, j, iR, jR) < RadiusSquared)
                        then rgbtRed := 255;
                     //紅色分量為255
                     if GFlag and (DistanceSquared(i, j, iG, jG) < RadiusSquared)
                        then rgbtGreen := 255;
                     //綠色分量為255
                     if BFlag and (DistanceSquared(i, j, iB, jB) < RadiusSquared)
                        then rgbtBlue := 255
                        //藍色分量為255
                  end
            end

      end
end ;

 創建CMYK分量圓:

function CreateCMYCircles(const size: INTEGER;
   const Cflag, Mflag, Yflag: BOOLEAN): TBitmap;
var
   AdjustedSize: INTEGER;
   Border: INTEGER;
   i, iC, iM, iY: INTEGER;
   j, jC, jM, jY: INTEGER;
   jOffset: INTEGER;
   RadiusSquared: INTEGER;
   row: pRGBTripleArray;

   function DistanceSquared(const x1, y1, x2, y2: INTEGER): INTEGER;
   begin
      RESULT := SQR(x1 - x2) + SQR(y1 - y2)
   end;

begin
   Border := MulDiv(size, 5, 1000);

   AdjustedSize := size - 2 * Border;

   RadiusSquared := SQR(MulDiv(AdjustedSize, 2, 6));

   iC := Border + MulDiv(AdjustedSize, 2, 6);
   iM := Border + MulDiv(AdjustedSize, 3, 6);
   iY := Border + MulDiv(AdjustedSize, 4, 6);
   //CMY顏色圈的點的橫坐標
   jOffset := ROUND(AdjustedSize * (2 - SQRT(3)) / 12);
   jC := jOffset + Border + Round(AdjustedSize * (2 + SQRT(3)) / 6);
   jM := jOffset + Border + MulDiv(AdjustedSize, 2, 6);
   jY := jC;
   //CMY顏色圈的點的縱坐標
   RESULT := TBitmap.Create;
   RESULT.Width := size;
   RESULT.Height := size;
   RESULT.PixelFormat := pf24bit;
   //創建輸出位圖
   RESULT.Canvas.Brush.Color := RGB(255, 255, 255); // white
   RESULT.Canvas.FillRect(RESULT.Canvas.ClipRect);
   //白色背景
   for j := 0 to RESULT.Height - 1 do
      begin
         row := RESULT.Scanline[j];

         for i := 0 to RESULT.Width - 1 do
            begin
               with row[i] do
                  begin
                     if Cflag and (DistanceSquared(i, j, iC, jC) < RadiusSquared)
                        then rgbtRed := 0;
                     //紅色分量為0
                     if MFlag and (DistanceSquared(i, j, iM, jM) < RadiusSquared)
                        then rgbtGreen := 0;
                     //綠色分量為0
                     if YFlag and (DistanceSquared(i, j, iY, jY) < RadiusSquared)
                        then rgbtBlue := 0;
                  end //藍色分量為0
            end

      end
end;



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved