MSN Messenger 6.1的正在登录界面的渐变背景色是如何画出来了?
我自己再Form的Paint事件中画渐变色,无法像Messenger那样平滑,很粗糙,一段一段的。
采用image控件+渐变的bmp图片也不行,也能明显看出来粗糙,但是这个色彩渐变图片在photoshop等图像处理软件中显示很平滑,请问这是什么原因?
是否程序能支持的色深有限?

解决方案 »

  1.   

    MSN Messenger 6.1的正在登录界面哪有渐变背景色?
      

  2.   

    最好使用API解决。
    需要使用下面一组库函数:CreatePen GetClientRect GetPixel GetSysColor  LineTo LockWindowUpdate  MoveToEx
      

  3.   

    自己解决了,用的windows api 继承了一个TPanel对象
    unit GradientPanel;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
      StdCtrls, ExtCtrls;
    type
      COLOR16 = word;
      TRIVERTEX = packed record
         x, y: dword;
         Red: COLOR16;
         Green: COLOR16;
         Blue: COLOR16;
         Alpha: COLOR16;
      end;  
    type 
      TColorStyle=(Horizontal,Vertical);
    type
      TGradientPanel = class(TPanel)
      private
        FColor1: TColor;
        FColor2: TColor;
        FColorStyle: TColorStyle;
        procedure SetColor1(const Value: TColor); 
        procedure SetColor2(const Value: TColor); 
        procedure SetColorStyle(const Value: TColorStyle); 
        { Private declarations }
      protected
        procedure Paint;override;
        { Protected declarations }
      public
        Constructor Create(AOwner:TComponent);override;
        { Public declarations }
      published
        property Color1:TColor read FColor1 Write SetColor1; 
        property Color2:TColor read FColor2 Write SetColor2; 
        property ColorStyle:TColorStyle read FColorStyle write SetColorStyle;
        { Published declarations }
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TGradientPanel]);
    end;function GradientFill(DC: hDC; pVertex: Pointer;
            dwNumVertex: DWORD; pMesh: Pointer;
            dwNumMesh, dwMode: DWORD): DWord; stdcall; external 'msimg32.dll';constructor TGradientPanel.Create(AOwner: TComponent);
    begin 
      inherited; 
      Width:=350; 
      Height:=40; 
      FColor1:=clRed;
      FColor2:=clWhite;
    end;procedure TGradientPanel.SetColor1(const Value: TColor);
    begin 
      FColor1 := Value; 
      Paint;
    end; procedure TGradientPanel.SetColor2(const Value: TColor);
    begin 
      FColor2 := Value;
      Paint; 
    end; procedure TGradientPanel.SetColorStyle(const Value: TColorStyle);
    begin 
      FColorStyle := Value; 
      Paint; 
    end;procedure TGradientPanel.Paint;
    var
      vert : array[0..1] of TRIVERTEX;
      gRect : GRADIENT_RECT;
      cl: LongInt;
    begin
      vert[0].x := 0;
      vert[0].y := 0;
      cl := ColorToRGB(FColor1);
      vert[0].Red := GetRvalue(cl) * 256;
      vert[0].Green := GetGValue(cl) * 256;
      vert[0].Blue := GetBValue(cl) * 256;
      vert[0].Alpha := $0000;
      vert[1].x := Width;
      vert[1].y := Height;
      cl := ColorToRGB(FColor2);
      vert[1].Red := GetRValue(cl) * 256;
      vert[1].Green := GetGValue(cl) * 256;
      vert[1].Blue := GetBValue(cl) * 256;
      vert[1].Alpha := $0000;
      gRect.UpperLeft := 0;
      gRect.LowerRight := 1;
      if FColorStyle=Vertical  then
        GradientFill(Canvas.Handle, @vert, 2, @gRect, 1, GRADIENT_FILL_RECT_V);
      if FColorStyle=Horizontal  then
        GradientFill(Canvas.Handle, @vert, 2, @gRect, 1, GRADIENT_FILL_RECT_H);
    end;end.
      

  4.   

    请问高手,我对这些几乎不懂,想学,你用的windows api是什么呀?下面写的一点都不懂。我学过pasic、C语言,我真的不知道你写的用的什么。不好意思,请各位指教!
      

  5.   

    我也刚用MSN Messenger 6.1,才对其中的NetMeeting会一点