怎样做这样的效果!把BMP变成(当一位图按钮的Enabled设为FALSE时Glyph的效果) (100分)

K

kasee

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样做这样的效果!把BMP变成(当一位图按钮的Enabled设为FALSE时Glyph的效果),
是浮雕?还是3D?最好能说说原理!

 
非常简单,就是将原来是黑色的地方用灰色填充,然后还要留下一个白色的阴影。

具体算法为:
var
i,j:Integer;
begin
with Image2 do //Image1和Image2的尺寸必须一致
begin
Canvas.Brush.Style:=bsSolid;
Canvas.Brush.Color:=clBtnface;
Canvas.FillRect(Rect(0,0,Width-1,Height-1)); //先用clBtnFace填充
for i:=0 to Height-1 do
for j:=0 to Width-1 do
if Image1.Canvas.Pixels[i,j]=clBlack then //如果Image1上的点是黑色...
begin
Canvas.Pixels[i,j]:=clGray; //变灰
Canvas.Pixels[i+1,j+1]:=clWhite; //阴影
end;
end;
end;
 
还有其它的方法吗?
我看别的原码只调了几个函数!不过就是搞不懂!
 
说说嘛!creation-zy的方法不太好,BMP大了效率好不好!
而且是用在控件的PAINT方法中!
 
其实不用编程来实现的。在PHOTOSHOP里做好一个图之后,再将它原样复制一份,去色,
加上浮雕效果。最后把两个图一左一右排好,合并成一个BMP。你把它赋给按钮的图片
属性,那么但你的按钮的ENABLED属性改变时,就可以实现你想要的效果。
可以看看DELPHI安装目录里(../Borland Shared/Images/Buttons/)的那些图片,都是这样
的.若你自己做的图片不能实现效果,就先到上述目录里随便找个图片赋值给按钮的图片
属性让按钮”感受“一下效果,然后再改成你自己做的图片,效果就跃然呈现了!
 
说说嘛!还有其它的方法吗?
 
1.Delphi 自带的一些 bitmap (common files下面) 有2~3 副子图,其中就有 Disable 的图。
2.如果想自己做可以这样,不要一个点一个点画(canvas.pixels),
用 canvas.draw 速度快,给个思路:
1。把原图变成2色的,Bitmap.format := pf2bit。
2。画在目标位置偏移(1,1)的位置上,其中白色为透明,黑色画成白色
3。画在目标位置偏移(-1,-1)的位置上,其中白色为透明,黑色画成深灰色
4。画在目标位置偏移(0,0)的位置上,其中白色为透明,黑色画成浅灰色
 
图像变灰:
procedure Gray(bmp: TBitmap);
var
p: PByteArray;
w: Integer;
i, j: Integer;
begin
bmp.pixelformat := pf24bit;
for i := 0 to bmp.height - 1 do
begin
p := bmp.scanline;
j := 0;
while j < (bmp.width-1) * 3 do
begin
w :=(p[j] * 28 + p[j+1] * 151 + p[j+2]*77);
w := w shr 8;
p[j] := byte(w);
p[j+1] := byte(w);
p[j+2] := byte(w);
inc(j, 3)
end;
end;
end;

**************************
//This function turns a colored Bitmap into Grayshades
uses
Windows, Graphics;

function ConvertBitmapToGrayscale1(const Bitmap: TBitmap): TBitmap;
var
i, j: Integer;
Grayshade, Red, Green, Blue: Byte;
PixelColor: Longint;
begin
with Bitmap do
for i := 0 to Width - 1 do
for j := 0 to Height - 1 do
begin
PixelColor := ColorToRGB(Canvas.Pixels[i, j]);
Red := PixelColor;
Green := PixelColor shr 8;
Blue := PixelColor shr 16;
Grayshade := Round(0.3 * Red + 0.6 * Green + 0.1 * Blue);
Canvas.Pixels[i, j] := RGB(Grayshade, Grayshade, Grayshade);
end;
Result := Bitmap;
end;



procedure ConvertBitmapToGrayscale2(const Bmp: TBitmap);
{From: Pascal Enz, pascal.enz@datacomm.ch }
type
TRGBArray = array[0..32767] of TRGBTriple;
PRGBArray = ^TRGBArray;
var
x, y, Gray: Integer;
Row: PRGBArray;
begin
Bmp.PixelFormat := pf24Bit;
for y := 0 to Bmp.Height - 1 do
begin
Row := Bmp.ScanLine[y];
for x := 0 to Bmp.Width - 1 do
begin
Gray := (Row[x].rgbtRed + Row[x].rgbtGreen + Row[x].rgbtBlue) div 3;
Row[x].rgbtRed := Gray;
Row[x].rgbtGreen := Gray;
Row[x].rgbtBlue := Gray;
end;
end;
end;


procedure ConvertBitmapToGrayscale3(const Bitmap: TBitmap);
type
PPixelRec = ^TPixelRec;
TPixelRec = packed record
B: Byte;
G: Byte;
R: Byte;
Reserved: Byte;
end;
var
X: Integer;
Y: Integer;
P: PPixelRec;
Gray: Byte;
begin
Assert(Bitmap.PixelFormat = pf32Bit);
for Y := 0 to (Bitmap.Height - 1) do
begin
P := Bitmap.ScanLine[Y];
for X := 0 to (Bitmap.Width - 1) do
begin
Gray := Round(0.30 * P.R + 0.59 * P.G + 0.11 * P.B);
// Gray := (P.R shr 2) + (P.R shr 4) + (P.G shr 1) + (P.G shr 4) + (P.B shr 3);
P.R := Gray;
P.G := Gray;
P.B := Gray;
Inc(P);
end;
end;
end;
 
多人接受答案了。
 
顶部