()
| 262 | } |
| 263 | |
| 264 | func (bmp *Bitmap) ToImage() (*image.RGBA, error) { |
| 265 | var bi win.BITMAPINFO |
| 266 | bi.BmiHeader.BiSize = uint32(unsafe.Sizeof(bi.BmiHeader)) |
| 267 | hdc := win.GetDC(0) |
| 268 | if ret := win.GetDIBits(hdc, bmp.hBmp, 0, 0, nil, &bi, win.DIB_RGB_COLORS); ret == 0 { |
| 269 | return nil, newError("GetDIBits get bitmapinfo failed") |
| 270 | } |
| 271 | |
| 272 | buf := make([]byte, bi.BmiHeader.BiSizeImage) |
| 273 | bi.BmiHeader.BiCompression = win.BI_RGB |
| 274 | if ret := win.GetDIBits(hdc, bmp.hBmp, 0, uint32(bi.BmiHeader.BiHeight), &buf[0], &bi, win.DIB_RGB_COLORS); ret == 0 { |
| 275 | return nil, newError("GetDIBits failed") |
| 276 | } |
| 277 | |
| 278 | width := int(bi.BmiHeader.BiWidth) |
| 279 | height := int(bi.BmiHeader.BiHeight) |
| 280 | img := image.NewRGBA(image.Rect(0, 0, width, height)) |
| 281 | |
| 282 | n := 0 |
| 283 | for y := 0; y < height; y++ { |
| 284 | for x := 0; x < width; x++ { |
| 285 | a := buf[n+3] |
| 286 | r := buf[n+2] |
| 287 | g := buf[n+1] |
| 288 | b := buf[n+0] |
| 289 | n += int(bi.BmiHeader.BiBitCount) / 8 |
| 290 | img.Set(x, height-y-1, color.RGBA{r, g, b, a}) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return img, nil |
| 295 | } |
| 296 | |
| 297 | func (bmp *Bitmap) hasTransparency() (bool, error) { |
| 298 | if bmp.transparencyStatus == transparencyUnknown { |
no test coverage detected