MCPcopy Create free account
hub / github.com/lxn/walk / NewBitmapFromImageWithSize

Function NewBitmapFromImageWithSize

bitmap.go:208–234  ·  view source on GitHub ↗

NewBitmapFromImageWithSize creates a bitmap with given size in native units and paints the image on it streched.

(image Image, size Size)

Source from the content-addressed store, hash-verified

206
207// NewBitmapFromImageWithSize creates a bitmap with given size in native units and paints the image on it streched.
208func NewBitmapFromImageWithSize(image Image, size Size) (*Bitmap, error) {
209 var disposables Disposables
210 defer disposables.Treat()
211
212 dpi := int(math.Round(float64(size.Width) / float64(image.Size().Width) * 96.0))
213 bmp, err := NewBitmapWithTransparentPixelsForDPI(size, dpi)
214 if err != nil {
215 return nil, err
216 }
217 disposables.Add(bmp)
218
219 canvas, err := NewCanvasFromImage(bmp)
220 if err != nil {
221 return nil, err
222 }
223 defer canvas.Dispose()
224
225 canvas.dpi = dpi
226
227 if err := canvas.DrawImageStretchedPixels(image, Rectangle{0, 0, size.Width, size.Height}); err != nil {
228 return nil, err
229 }
230
231 disposables.Spare()
232
233 return bmp, nil
234}
235
236func NewBitmapFromWindow(window Window) (*Bitmap, error) {
237 hBmp, err := hBitmapFromWindow(window)

Callers 3

NewIconFromImageWithSizeFunction · 0.85
newIconFromImageForDPIFunction · 0.85
BitmapMethod · 0.85

Calls 8

TreatMethod · 0.95
AddMethod · 0.95
SpareMethod · 0.95
NewCanvasFromImageFunction · 0.85
SizeMethod · 0.65
DisposeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…