四、位图图案窗体的创建<br><br>1、位图图案区域数据的生成函数GetRgnData<br><br>procedure GetRgnData (Bmp: TBitmap; var nCount: Cardinal; var lpRgnData: PRgnData);<br><br>var<br><br>h, w, i, j: Integer;<br><br>tc: TColor;<br><br>hrgn1, hrgn2: HRGN;<br><br>begin<br><br>h := Bmp.Height;<br><br>w := Bmp.Width;<br><br>//获取位图第一象素点的颜色值,背景颜色<br><br>tc := Bmp.Canvas.Pixels[0, 0];<br><br>//生成矩形区域<br><br>hrgn1 := CreateRectRgn (0, 0, w, h);<br><br><br>try<br><br>for i := 0 to h-1 do<br><br>begin<br><br>for j := 0 to w-1 do<br><br>begin<br><br>//判断当前象素点的颜色值是否与背景色相同<br><br>if Bmp.Canvas.Pixels[j, i] = tc then <br><br>begin<br><br>hrgn2 := CreateRectRgn (j, i, j+1, i+1);<br><br>if hrgn2 <> 0 then<br><br>//抠去hrgn2数据区域<br><br>CombineRgn (hrgn1, hrgn1, hrgn2, RGN_DIFF); <br><br><br>DeleteObject (hrgn2);<br><br>end;<br><br>end;<br><br>end;<br><br><br>//获取hrgn1数据区域大小<br><br>nCount := GetRegionData (hrgn1, 0, nil); <br><br>//分配内存空间给临时区域指针lpRgnData<br><br>GetMem (lpRgnData, nCount * sizeof(TRgnData));<br><br>//获取数据<br><br>GetRegionData (hrgn1, nCount, lpRgnData);<br><br>except<br><br>ShowMessage ('区域数据生成出错');<br><br>end;<br><br>DeleteObject (hrgn1);<br><br>end;