本文整理汇总了Golang中image.NewAlpha函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAlpha函数的具体用法?Golang NewAlpha怎么用?Golang NewAlpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAlpha函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: initLayout
// initLayout constructs two masks for drawing the battery and the remaining
// energy as well as sets the pixel bounds for drawing energy capacity. the
// masks allow for simplified space-fills and reduced chance of pixel gaps.
func (app *App) initLayout() {
var zeropt image.Point
rectOutTop := image.Rectangle{Min: app.Layout.battRect.Min, Max: app.Layout.battRect.Min.Add(image.Point{2, 2})}
rectOutBottom := rectOutTop.Add(image.Point{Y: app.Layout.battRect.Size().Y - rectOutTop.Size().Y})
capRect := image.Rectangle{
Min: image.Point{X: rectOutTop.Min.X, Y: rectOutTop.Max.Y},
Max: image.Point{X: rectOutBottom.Max.X, Y: rectOutBottom.Min.Y},
}
bodyRect := app.Layout.battRect
bodyRect.Min.X = capRect.Max.X
// energy will be drawn under the battery shell. The only place where it
// is not safe to draw energy is outside the battery on the positive end.
energyMask := image.NewAlpha(app.Layout.battRect)
draw.Draw(energyMask, app.Layout.battRect, opaque, zeropt, draw.Over)
draw.Draw(energyMask, rectOutTop, transparent, zeropt, draw.Src)
draw.Draw(energyMask, rectOutBottom, transparent, zeropt, draw.Src)
app.maskEnergy = energyMask
// the body uses the same mask as the energy with additional transparency
// inside the battery's shell. the mask construction is complex because
// area inside the cap may be exposed.
bodyMask := image.NewAlpha(app.Layout.battRect)
draw.Draw(bodyMask, app.Layout.battRect, energyMask, app.Layout.battRect.Min, draw.Over)
bodyMaskRect := shrinkRect(bodyRect, app.Layout.thickness)
draw.Draw(bodyMask, bodyMaskRect, transparent, zeropt, draw.Src)
capMaskRect := shrinkRect(capRect, app.Layout.thickness)
capMaskRect.Max.X += 2 * app.Layout.thickness
draw.Draw(bodyMask, capMaskRect, transparent, zeropt, draw.Src)
app.maskBattery = bodyMask
// create a freetype.Context to render text. each time the context is used
// it must have its SetDst method called.
app.tt = freetype.NewContext()
app.tt.SetSrc(black)
app.tt.SetClip(app.Layout.textRect)
app.tt.SetDPI(app.Layout.DPI)
app.tt.SetFont(app.Layout.font)
app.tt.SetFontSize(app.Layout.fontSize)
ttopt := &truetype.Options{
Size: app.Layout.fontSize,
DPI: app.Layout.DPI,
}
ttface := truetype.NewFace(app.Layout.font, ttopt)
app.font = &font.Drawer{
Src: black,
Face: ttface,
}
// the rectangle in which energy is drawn needs to account for thickness to
// make the visible percentage more accurate. after adjustment reduce the
// energy rect to account for the account of energy drained. the energy
// mask makes computing Y bounds largely irrelevant.
app.minEnergy = capMaskRect.Min.X
app.maxEnergy = bodyMaskRect.Max.X
}
开发者ID:bmatsuo,项目名称:dockapp-go,代码行数:60,代码来源:main.go
示例2: NewDrawableSize
// NewDrawableSize returns a new draw.Image with the same type as p and the given bounds.
// If p is not a draw.Image, another type is used.
func NewDrawableSize(p image.Image, r image.Rectangle) draw.Image {
switch p := p.(type) {
case *image.RGBA:
return image.NewRGBA(r)
case *image.RGBA64:
return image.NewRGBA64(r)
case *image.NRGBA:
return image.NewNRGBA(r)
case *image.NRGBA64:
return image.NewNRGBA64(r)
case *image.Alpha:
return image.NewAlpha(r)
case *image.Alpha16:
return image.NewAlpha16(r)
case *image.Gray:
return image.NewGray(r)
case *image.Gray16:
return image.NewGray16(r)
case *image.Paletted:
pl := make(color.Palette, len(p.Palette))
copy(pl, p.Palette)
return image.NewPaletted(r, pl)
case *image.CMYK:
return image.NewCMYK(r)
default:
return image.NewRGBA(r)
}
}
开发者ID:cautio,项目名称:imageserver,代码行数:30,代码来源:util.go
示例3: rasterize
// rasterize returns the advance width, glyph mask and integer-pixel offset
// to render the given glyph at the given sub-pixel offsets.
// The 24.8 fixed point arguments fx and fy must be in the range [0, 1).
func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (
raster.Fix32, *image.Alpha, image.Point, error) {
if err := c.glyphBuf.Load(c.font, c.scale, glyph, truetype.Hinting(c.hinting)); err != nil {
return 0, nil, image.Point{}, err
}
// Calculate the integer-pixel bounds for the glyph.
xmin := int(fx+raster.Fix32(c.glyphBuf.B.XMin<<2)) >> 8
ymin := int(fy-raster.Fix32(c.glyphBuf.B.YMax<<2)) >> 8
xmax := int(fx+raster.Fix32(c.glyphBuf.B.XMax<<2)+0xff) >> 8
ymax := int(fy-raster.Fix32(c.glyphBuf.B.YMin<<2)+0xff) >> 8
if xmin > xmax || ymin > ymax {
return 0, nil, image.Point{}, errors.New("freetype: negative sized glyph")
}
// A TrueType's glyph's nodes can have negative co-ordinates, but the
// rasterizer clips anything left of x=0 or above y=0. xmin and ymin
// are the pixel offsets, based on the font's FUnit metrics, that let
// a negative co-ordinate in TrueType space be non-negative in
// rasterizer space. xmin and ymin are typically <= 0.
fx += raster.Fix32(-xmin << 8)
fy += raster.Fix32(-ymin << 8)
// Rasterize the glyph's vectors.
c.r.Clear()
e0 := 0
for _, e1 := range c.glyphBuf.End {
c.drawContour(c.glyphBuf.Point[e0:e1], fx, fy)
e0 = e1
}
a := image.NewAlpha(image.Rect(0, 0, xmax-xmin, ymax-ymin))
c.r.Rasterize(raster.NewAlphaSrcPainter(a))
return raster.Fix32(c.glyphBuf.AdvanceWidth << 2), a, image.Point{xmin, ymin}, nil
}
开发者ID:smalllixin,项目名称:freetype-go,代码行数:35,代码来源:freetype.go
示例4: textBox
// textBox renders t into a tight fitting image
func (ig *ImageGraphics) textBox(t string, size int) image.Image {
// Initialize the context.
fg := image.NewUniform(color.Alpha{0xff})
bg := image.NewUniform(color.Alpha{0x00})
canvas := image.NewAlpha(image.Rect(0, 0, 400, 2*size))
draw.Draw(canvas, canvas.Bounds(), bg, image.ZP, draw.Src)
c := freetype.NewContext()
c.SetDPI(dpi)
c.SetFont(ig.font)
c.SetFontSize(float64(size))
c.SetClip(canvas.Bounds())
c.SetDst(canvas)
c.SetSrc(fg)
// Draw the text.
h := c.FUnitToPixelRU(ig.font.UnitsPerEm())
pt := freetype.Pt(0, h)
extent, err := c.DrawString(t, pt)
if err != nil {
log.Println(err)
return nil
}
// log.Printf("text %q, extent: %v", t, extent)
return canvas.SubImage(image.Rect(0, 0, int(extent.X/256), h*5/4))
}
开发者ID:ajstarks,项目名称:chart,代码行数:27,代码来源:image.go
示例5: main
func main() {
var err error
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
fiveyearsImage, _, err = common.AssetImage("fiveyears.jpg", ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
maskImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
as := image.Point{128, 128}
a := image.NewAlpha(image.Rectangle{image.ZP, as})
for j := 0; j < as.Y; j++ {
for i := 0; i < as.X; i++ {
r := as.X / 2
d := math.Sqrt(float64((i-r)*(i-r) + (j-r)*(j-r)))
b := uint8(max(0, min(0xff, 3*0xff-int(d*3*0xff)/r)))
a.SetAlpha(i, j, color.Alpha{b})
}
}
spotLightImage, err = ebiten.NewImageFromImage(a, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Masking (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
}
开发者ID:carriercomm,项目名称:ebiten,代码行数:33,代码来源:main.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng