@@ -22,7 +22,7 @@ const inchesPerMeter = 39.37007874
2222type Bitmap struct {
2323 hBmp win.HBITMAP
2424 hPackedDIB win.HGLOBAL
25- size SizePixels
25+ size Size // in native pixels
2626 dpi int
2727}
2828
@@ -39,33 +39,34 @@ func BitmapFrom(src interface{}, dpi int) (*Bitmap, error) {
3939 return iconCache .Bitmap (img , dpi )
4040}
4141
42- // NewBitmap creates an opaque bitmap with given size at screen DPI.
42+ // NewBitmap creates an opaque bitmap with given size in 1/96" units at screen DPI.
4343//
4444// Deprecated: Newer applications should use NewBitmapForDPI.
4545func NewBitmap (size Size ) (* Bitmap , error ) {
4646 dpi := screenDPI ()
4747 return newBitmap (SizeFrom96DPI (size , dpi ), false , dpi )
4848}
4949
50- // NewBitmapForDPI creates an opaque bitmap with given size and DPI.
51- func NewBitmapForDPI (size SizePixels , dpi int ) (* Bitmap , error ) {
50+ // NewBitmapForDPI creates an opaque bitmap with given size in native pixels and DPI.
51+ func NewBitmapForDPI (size Size , dpi int ) (* Bitmap , error ) {
5252 return newBitmap (size , false , dpi )
5353}
5454
55- // NewBitmapWithTransparentPixels creates a transparent bitmap with given size at screen DPI.
55+ // NewBitmapWithTransparentPixels creates a transparent bitmap with given size in 1/96" units at screen DPI.
5656//
5757// Deprecated: Newer applications should use NewBitmapWithTransparentPixelsForDPI.
5858func NewBitmapWithTransparentPixels (size Size ) (* Bitmap , error ) {
5959 dpi := screenDPI ()
6060 return newBitmap (SizeFrom96DPI (size , dpi ), true , dpi )
6161}
6262
63- // NewBitmapWithTransparentPixelsForDPI creates a transparent bitmap with given size and DPI.
64- func NewBitmapWithTransparentPixelsForDPI (size SizePixels , dpi int ) (* Bitmap , error ) {
63+ // NewBitmapWithTransparentPixelsForDPI creates a transparent bitmap with given size in native pixels and DPI.
64+ func NewBitmapWithTransparentPixelsForDPI (size Size , dpi int ) (* Bitmap , error ) {
6565 return newBitmap (size , true , dpi )
6666}
6767
68- func newBitmap (size SizePixels , transparent bool , dpi int ) (bmp * Bitmap , err error ) {
68+ // newBitmap creates a bitmap with given size in native pixels and DPI.
69+ func newBitmap (size Size , transparent bool , dpi int ) (bmp * Bitmap , err error ) {
6970 err = withCompatibleDC (func (hdc win.HDC ) error {
7071 bufSize := int (size .Width * size .Height * 4 )
7172
@@ -194,7 +195,8 @@ func newBitmapFromResource(res *uint16, dpi int) (bm *Bitmap, err error) {
194195 return
195196}
196197
197- func NewBitmapFromImageWithSize (image Image , size SizePixels ) (* Bitmap , error ) {
198+ // NewBitmapFromImageWithSize creates a bitmap with given size in native units and paints the image on it streched.
199+ func NewBitmapFromImageWithSize (image Image , size Size ) (* Bitmap , error ) {
198200 var disposables Disposables
199201 defer disposables .Treat ()
200202
@@ -231,15 +233,17 @@ func NewBitmapFromWindow(window Window) (*Bitmap, error) {
231233 return newBitmapFromHBITMAP (hBmp , window .DPI ())
232234}
233235
234- // NewBitmapFromIcon creates a new bitmap with given size and 96dpi and paints the icon on it.
236+ // NewBitmapFromIcon creates a new bitmap with given size in native pixels and 96dpi and paints the
237+ // icon on it.
235238//
236239// Deprecated: Newer applications should use NewBitmapFromIconForDPI.
237- func NewBitmapFromIcon (icon * Icon , size SizePixels ) (* Bitmap , error ) {
240+ func NewBitmapFromIcon (icon * Icon , size Size ) (* Bitmap , error ) {
238241 return NewBitmapFromIconForDPI (icon , size , 96 )
239242}
240243
241- // NewBitmapFromIconForDPI creates a new bitmap with given size and DPI and paints the icon on it.
242- func NewBitmapFromIconForDPI (icon * Icon , size SizePixels , dpi int ) (* Bitmap , error ) {
244+ // NewBitmapFromIconForDPI creates a new bitmap with given size in native pixels and DPI and paints
245+ // the icon on it.
246+ func NewBitmapFromIconForDPI (icon * Icon , size Size , dpi int ) (* Bitmap , error ) {
243247 hBmp , err := hBitmapFromIcon (icon , size , dpi )
244248 if err != nil {
245249 return nil , err
@@ -420,7 +424,7 @@ func newBitmapFromHBITMAP(hBmp win.HBITMAP, dpi int) (bmp *Bitmap, err error) {
420424 return & Bitmap {
421425 hBmp : hBmp ,
422426 hPackedDIB : hPackedDIB ,
423- size : SizePixels {
427+ size : Size {
424428 int (bmih .BiWidth ),
425429 int (bmih .BiHeight ),
426430 },
@@ -501,7 +505,9 @@ func hBitmapFromWindow(window Window) (win.HBITMAP, error) {
501505 return hBmp , nil
502506}
503507
504- func hBitmapFromIcon (icon * Icon , size SizePixels , dpi int ) (win.HBITMAP , error ) {
508+ // hBitmapFromIcon creates a new win.HBITMAP with given size in native pixels and DPI, and paints
509+ // the icon on it stretched.
510+ func hBitmapFromIcon (icon * Icon , size Size , dpi int ) (win.HBITMAP , error ) {
505511 hdc := win .GetDC (0 )
506512 defer win .ReleaseDC (0 , hdc )
507513
0 commit comments