在调色板中确定一种颜色的索引值(50分)

Z

zjh2002

Unregistered / Unconfirmed
GUEST, unregistred user!
我要用颜色对话框中的颜色替换位图中的某种颜色,为了速度快,我用了scanline.可是我没法得到
对话框种颜色在位图调色板中的索引值.即
p:pbytearray;
p:=newcolor;
中的newcolor,它应该是一个0到255的值.
 
0-255?

是6位16进制么?

关注关注
 
ColorToRGB() 查查delphi的在线帮助文件
 
怎么没有人回答阿,很难吗?那将颜色对话框中的颜色转为调色板中的索引值怎么办啊.
 
>ColorToRGB() 查查delphi的在线帮助文件
返回的是longint,肯定不行的。贴一个例子有关调色板的:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
x,y : integer;
BitMap : TBitMap;
lplogpal:pMaxLogPalette;//pointer of TMaxLogPalette
p:pByteArray;
begin
BitMap := TBitMap.create;
Bitmap.Width:=form1.Width;
Bitmap.Height:=form1.Height;
Bitmap.PixelFormat:= pf8bit;
// randomize;
GetMem(lpLogPal,sizeof(TLOGPALETTE) + ((255) * sizeof(TPALETTEENTRY)));
lpLogPal.palVersion := $0300; //the current palette version
lpLogPal.palNumEntries := 256;
for x := 0 to 255 do
begin
lpLogPal.palPalEntry[x].peRed := 255;//x*23
lpLogPal.palPalEntry[x].peGreen :=x;
lpLogPal.palPalEntry[x].peBlue := random(127);
end;
Bitmap.Palette := CreatePalette(pLogPalette(lpLogPal)^);
FreeMem(lpLogPal,sizeof(TLOGPALETTE) + ((255) * sizeof(TPALETTEENTRY)));
for y := 0 to BitMap.Height -1 do
begin
P := BitMap.ScanLine[y];
for x := 0 to BitMap.Width -1 do
P[x] :=byte( (y*x));//ÕâÀï²»ÀàÐÍת»»Ò»ÏÂÒ²»áRange Checking´í
end;
canvas.draw(0,0,BitMap);//form.canvas, just for a look:)
end;


end.
 
要用系统调色板的颜色替代你的颜色是吗?
那么用GetNearestColor。
The GetNearestColor function returns a color value identifying a color from the system palette that will be displayed when the specified color value is used.

COLORREF GetNearestColor(

HDC hdc, // handle of device context
COLORREF crColor // color to be matched
);
 
谢谢雪鹰了,不过好像getnearestpaletteindex更好一些。在你的启发下找出来的。
 
多人接受答案了。
 
顶部