線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1650
推到 Plurk!
推到 Facebook!

請問*.ICO檔如何不失真的轉為*.BMP格式?

尚未結案
jenpeter
一般會員


發表:39
回覆:37
積分:15
註冊:2002-08-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-10-16 19:59:26 IP:218.163.xxx.xxx 未訂閱
我在站上找到了一個範例(附A)可以把 ICO格式轉為BMP的格式. 換完成後的BMP格式卻無作灰階處理(附B),有那位先進可以指導 一下問題所在嗎?謝謝 我的 程式如下: 附A:ICO轉BMP FUNCCTION procedure ConvertIcon2Bitmap(Icon : TIcon; TransColor : TColor; var Bitmap : TBitmap); { Convert the supplied icon into a proper bitmap for Delphi button glyphs and return in Bitmap. Use TransColor for the transparent color in the Bitmap. See the demo program for examples on usage. } var i,j : integer; { loop control variables } IconInfo : TIconInfo; { information about the icon } ANDmask : TBitmap; { the AND mask of the icon } OldMaskColor : TColor; { keep track of last color in AND mask } NewMaskColor : TColor; { the current color in the AND mask } begin { convertIcon2Bitmap } { create bitmap for the icon AND mask information } ANDmask := TBitmap.Create; try { Get the icon information and place the AND mask into the appropriate TBitmap structure } GetIconInfo(Icon.Handle,IconInfo); ANDmask.Handle := IconInfo.hbmMask; { Set the returning bitmap size and draw the icon onto it } Bitmap.Width := ANDmask.Width; Bitmap.Height := ANDmask.Height 1; { add one line onto the bottom of the bitmap to keep the Delphi glyph happy } Bitmap.Canvas.Draw(0,0,Icon); { Where the ANDmask bitmap is transparent, place the transparent color } Bitmap.Canvas.Pen.Color := TransColor; for j := 0 to ANDmask.Height - 1 do begin { for j } OldMaskColor := clRed; { start off with a color that is not in the mask } Bitmap.Canvas.MoveTo(0,j); { move the the first pixel of this row } for i := 0 to ANDmask.Width - 1 do begin { for i } NewMaskColor := GetPixel(ANDmask.Canvas.Handle,i,j); { get pixel color } if NewMaskColor <> OldMaskColor then begin { NewMaskColor <> OldMaskColor } { if the pixel is not the same color as the last pixel then we have a trasition -- either from transparent or to transparent colors } OldMaskColor := NewMaskColor; if NewMaskColor = clWhite then { transition from solid to transparent -- move to the first pixel of the transparent region } Bitmap.Canvas.MoveTo(i,j) else { transition from transparent to solid -- draw a line through the transparent region in the transparent color } Bitmap.Canvas.LineTo(i,j); end; { NewMaskColor <> OldMaskColor } end; { for i } { if the line ends with a transparent color then draw a line through the transparent region in the transparent color } if NewMaskColor = clWhite then Bitmap.Canvas.LineTo(ANDmask.Width,j); end; { for j } { place an extra line at the bottom of the bitmap so that the Delphi TSpeedButton transparent color works correctly } Bitmap.Canvas.MoveTo(0,Bitmap.Height - 1); Bitmap.Canvas.LineTo(Bitmap.Width,Bitmap.Height - 1); finally { Release the memory for the icon information } ANDmask.Free; end; { try..finally } end; { ConvertIcon2Bitmap } 附 B. BMP彩色轉 灰階FUNCTION procedure Grayscale(const Bitmap:TBitmap); var X: Integer; Y: Integer; PRGB: pRGBTriple; Gray: Byte; begin for Y := 0 to (Bitmap.Height - 1) do begin PRGB := Bitmap.ScanLine[Y]; for X := 0 to (Bitmap.Width - 1) do begin Gray := Trunc(0.3 * PRGB^.rgbtRed 0.59 * PRGB^.rgbtGreen 0.11 * PRGB^.rgbtBlue); PRGB^.rgbtRed:=Gray; PRGB^.rgbtGreen:=Gray; PRGB^.rgbtBlue:=Gray; Inc(PRGB); end; end; end;
syntax
尊榮會員


發表:26
回覆:1139
積分:1258
註冊:2002-04-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-10-18 17:47:41 IP:203.222.xxx.xxx 未訂閱
卻無作灰階處理(附B) 你的程式中 ConvertIcon2Bitmap() 未見你使用 Grayscale() 所以不知你使否有使用 Grayscale() ?
jenpeter
一般會員


發表:39
回覆:37
積分:15
註冊:2002-08-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-10-21 06:03:31 IP:218.163.xxx.xxx 未訂閱
有使用~但轉之後圖形變的很亂.
系統時間:2024-05-08 0:31:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!