程序中用的图标按钮,以前的做法是做多种状态的图标,鼠标移入移出时,换图.但是这样有多少种图标,就得做多少个图.我想通过实时处理图标,获得不同状态的图标.查了N多资料,ICO的几乎找不到,只有BMP的处理函数.于是把ICO转BMP,再进行处理.这样的话,感觉效果不怎么好,效率也低.有没有方法直接处理ICO的文件,而且不造成失真.附ICO转BMP方法实现的处理代码://image1导入测试ico图标
//image2显示处理后的图标//将ICO画在IMAGE2上
Image2.Picture:=nil;
Image1.Picture.Icon;
image2.Picture.Bitmap.Height:=Image1.Picture.Icon.Height+16;
image2.Picture.Bitmap.Width :=Image1.Picture.Icon.Width+16;
image2.Picture.Bitmap.Canvas.Draw(0, 0, Image1.Picture.Icon );//对IMAGE2上的图象进行处理
Image2.Picture:=nil;
Image1.Picture.Icon;
image2.Picture.Bitmap.Height:=Image1.Picture.Icon.Height+16;
image2.Picture.Bitmap.Width :=Image1.Picture.Icon.Width+16;
image2.Picture.Bitmap.Canvas.Draw(0, 0, Image1.Picture.Icon );
ChangeBrightness(image2.Picture.Bitmap,-30);
//bmp亮度调节
function ChangeBrightness(bmp: TBitmap; s: Integer): Boolean; varp: PByteArray; x, y: Integer; begin try //24位真彩色 Bmp.PixelFormat := pf24Bit; bmp.Canvas.Lock; for y := 0 to Bmp.Height - 1 do begin p := Bmp.scanline[y]; for x := 0 to Bmp.Width - 1 do begin //每个象素点的R、G、B分量进行调节 begin if s > 0 then begin p[x * 3] := Min(255, p[x * 3] + s); //不能越界,限制在0~255 p[x * 3 + 1] := Min(255, p[x * 3 + 1] + s); p[x * 3 + 2] := Min(255, p[x * 3 + 2] + s); end else begin p[x * 3] := max(0, p[x * 3] + s); //不能越界,限制在-255~0 p[x * 3 + 1] := max(0, p[x * 3 + 1] + s); p[x * 3 + 2] := max(0, p[x * 3 + 2] + s); end; end; end; end; bmp.Canvas.Unlock; Result := true; except Result := false; end; end;
//image2显示处理后的图标//将ICO画在IMAGE2上
Image2.Picture:=nil;
Image1.Picture.Icon;
image2.Picture.Bitmap.Height:=Image1.Picture.Icon.Height+16;
image2.Picture.Bitmap.Width :=Image1.Picture.Icon.Width+16;
image2.Picture.Bitmap.Canvas.Draw(0, 0, Image1.Picture.Icon );//对IMAGE2上的图象进行处理
Image2.Picture:=nil;
Image1.Picture.Icon;
image2.Picture.Bitmap.Height:=Image1.Picture.Icon.Height+16;
image2.Picture.Bitmap.Width :=Image1.Picture.Icon.Width+16;
image2.Picture.Bitmap.Canvas.Draw(0, 0, Image1.Picture.Icon );
ChangeBrightness(image2.Picture.Bitmap,-30);
//bmp亮度调节
function ChangeBrightness(bmp: TBitmap; s: Integer): Boolean; varp: PByteArray; x, y: Integer; begin try //24位真彩色 Bmp.PixelFormat := pf24Bit; bmp.Canvas.Lock; for y := 0 to Bmp.Height - 1 do begin p := Bmp.scanline[y]; for x := 0 to Bmp.Width - 1 do begin //每个象素点的R、G、B分量进行调节 begin if s > 0 then begin p[x * 3] := Min(255, p[x * 3] + s); //不能越界,限制在0~255 p[x * 3 + 1] := Min(255, p[x * 3 + 1] + s); p[x * 3 + 2] := Min(255, p[x * 3 + 2] + s); end else begin p[x * 3] := max(0, p[x * 3] + s); //不能越界,限制在-255~0 p[x * 3 + 1] := max(0, p[x * 3 + 1] + s); p[x * 3 + 2] := max(0, p[x * 3 + 2] + s); end; end; end; end; bmp.Canvas.Unlock; Result := true; except Result := false; end; end;
解决方案 »
- 自定义控件加到控件栏
- 用什么方法能得到MonthCalendar的一个月中第一天和最后一天,跨年时出问题了。
- Delphi 2007 打开工程错误!
- 求救,网络视频压缩+传输(有代码)
- 如何执行带有redirect文件的可执行文件【D:\压缩文件.exe < D:password.txt】
- 答完立即给分,有关listbox中数据删除的
- 用程序将sqlserver中的一张表的数据插入到access中的一张表,表的结构是一样的,如果实现呢
- Delphi使用什么函数检验字符串是不是数字??如:‘1234’是字符串的数字。
- 谁知道哪里有epson ESC/Pos指令集的下载
- 各位兄弟,这是个系统问题,请帮忙,100分!
- 请教下如何替换一段xml文档的内容呢?delphi
- 如何显示series编号
第一张是原图,
第二张是处理后,未设透明的效果。
第三张是处理后,设透明的效果。原图因为是ICO,边角是透明的,但是转为BMP时,边角变为了白色。
如果不设边角透明,则处理过后的图标,边角多了白色。如果设为透明,则图形中间部分与边角同色的区域也被透明了。这问题如何解决。请指点如果解决?
http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece76310508a24420597634b86914323c3933fcf331d5c017be3b92524120fd0c7616703b2485deef33070321420c0c18ed714c9fecf6879877c652d0b873105a26eb8ba4032b151872e9eb81897ad803884dad1c4ae2744ba25&p=86759a4e8f9812a05ea2c2271b&user=baidu&fm=sc&query=ico%CE%C4%BC%FE%B8%F1%CA%BD&qid=c6c4ba590c37d6d4&p1=8
你到网上找下GDI+的学习资料吧。你给这点分我懒得帮你写现成代码。