 
			
				01.09.2011, 11:18
			
			
			
		  
	 | 
	
		
		
		
			  | 
			
			
				
				
				 Let Me Show You 
				
				
			 | 
			  | 
			
				
				
					Регистрация: 30.04.2010 
					Адрес: Северодвинск 
					
					Сообщения: 5,426
 
				Версия Delphi: 7, XE5 
					Репутация: 59586 
					    
				 
				
			 | 
		 
		 
		
	 | 
	
	
	
		
			
			
				 
				
			 
			 
			
		
		
		
		а чем способ MS ( GetNearestPaletteIndex) не подходит?
 
	Цитата: 
	
	
		
			
				GetNearestPaletteIndex Function 
The GetNearestPaletteIndex function retrieves the index for the entry in the specified logical palette most closely matching a specified color value. 
 
Syntax 
 
UINT GetNearestPaletteIndex( 
  __in  HPALETTE hpal, 
  __in  COLORREF crColor 
); 
 
Parameters 
 
hpal [in] 
A handle to a logical palette. 
 
crColor [in] 
A color to be matched. To create a COLORREF color value, use the RGB macro. 
 
Return Value 
 
If the function succeeds, the return value is the index of an entry in a logical palette. 
 
If the function fails, the return value is CLR_INVALID.
			
		 | 
	 
	 
 
http://msdn.microsoft.com/en-us/libr...03(VS.85).aspx
	Цитата: 
	
	
		
			
				function GetNearestPaletteIndex(p1: HPALETTE; p2: COLORREF): UINT; stdcall; 
 
Получает ближайший совпадающий с Color цвет в логической палитpе.
			
		 | 
	 
	 
 
функция:
	Код: 
	function GetNearestColorFromEntries(const Entries: array of DWORD;
  const AColor: DWORD): DWORD;
var
  LogPalette: TMaxLogPalette;
  APalette: HPALETTE;
  crColor: Cardinal;
begin
  LogPalette.palVersion:=$300;
  LogPalette.palNumEntries:=High(Entries)-Low(Entries)+1;
  Move(Entries, LogPalette.palPalEntry[0],
    SizeOf(DWORD)*LogPalette.palNumEntries);
  APalette:=CreatePalette(PLogPalette(@LogPalette)^);
  crColor:=GetNearestPaletteIndex(APalette, AColor);
  DeleteObject(APalette);
  if crColor<>CLR_INVALID then
    Result:=RGB(LogPalette.palPalEntry[crColor].peRed,
      LogPalette.palPalEntry[crColor].peGreen,
      LogPalette.palPalEntry[crColor].peBlue)
  else Result:=AColor;
end; 
 
использование:
	Код: 
	type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Edit1: TEdit;
    Panel2: TPanel;
    Edit2: TEdit; 
 
	Код: 
	var
  c: DWORD;
begin
  c:=$20c0c0;
  Panel1.Color:=c;
  Edit1.Text:=IntToHex(c, 8);
  c:=GetNearestColorFromEntries([$000000, $0000ff, $00ff00, $ff0000, $00ffff, $ff00ff, $ffff00, $ffffff], c);
  Panel2.Color:=c;
  Edit2.Text:=IntToHex(c, 8);
end;  
 
	Код: 
	const
  Pal16: array [0..15] of DWORD =
    (clBlack, clMaroon, clGreen, clOlive, clNavy, clPurple, clTeal, clDkGray,
     clLtGray, clRed, clLime, clYellow, clBlue, clFuchsia, clAqua, clWhite);
var
  c: DWORD;
begin
  c:=$604020;
  Panel1.Color:=c;
  Edit1.Text:=IntToHex(c, 8);
  c:=GetNearestColorFromEntries(Pal16, c);
  Panel2.Color:=c;
  Edit2.Text:=IntToHex(c, 8);
end; 
 
	Код: 
	var
  Entries: array of DWORD;
  i: Integer;
  c: DWORD;
begin
  c:=$604020;
  Panel1.Color:=c;
  Edit1.Text:=IntToHex(c, 8);
  SetLength(Entries, 256);
  for i:=0 to 255 do Entries[i]:=i;
  c:=GetNearestColorFromEntries(Entries, c);
  Panel2.Color:=c;
  Edit2.Text:=IntToHex(c, 8);
end;  
  
		
	
		
		
		
		
			
		
		
		
		
	
		
		
	
	
	 |