本文整理汇总了Golang中image.Image函数的典型用法代码示例。如果您正苦于以下问题:Golang Image函数的具体用法?Golang Image怎么用?Golang Image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Image函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RevisitMsg
func (ri *RevisitImage) RevisitMsg() (*RevisitMsg, error) {
buf := bytes.NewBuffer(nil)
switch ri.ImgType {
case "image/jpeg":
err := jpeg.Encode(buf, image.Image(image.Image(&ri.Rgbas[0])), nil)
if err != nil {
return nil, err
}
case "image/png":
err := png.Encode(buf, image.Image(&ri.Rgbas[0]))
if err != nil {
return nil, err
}
case "image/gif":
g := &gif.GIF{
Image: make([]*image.Paletted, 0),
LoopCount: ri.LoopCount,
Delay: make([]int, 0),
}
for index, src := range ri.Rgbas {
b := src.Bounds()
pal := image.NewPaletted(image.Rect(0, 0, b.Dx(), b.Dy()), ri.Palette[index])
draw.Draw(pal, pal.Bounds(), image.Image(&src), b.Min, draw.Src)
g.Image = append(g.Image, pal)
g.Delay = append(g.Delay, ri.Delay[index])
}
buf := bytes.NewBuffer(nil)
err := gif.EncodeAll(buf, g)
if err != nil {
return nil, err
}
dstImgBase64 := base64.StdEncoding.EncodeToString(buf.Bytes())
return &RevisitMsg{
Content: ImageData{
Data: fmt.Sprintf("data:%s;base64,%s", ri.ImgType, dstImgBase64),
},
}, nil
default:
return nil, errors.New("invalid image type")
}
dstImgBase64 := base64.StdEncoding.EncodeToString(buf.Bytes())
return &RevisitMsg{
Content: ImageData{
Data: fmt.Sprintf("data:%s;base64,%s", ri.ImgType, dstImgBase64),
},
}, nil
}
开发者ID:revisitors,项目名称:gorevisit,代码行数:56,代码来源:revisit_image.go
示例2: ImageTransformByProfile
func ImageTransformByProfile(src_image image.Image, src_prof, dst_prof *Profile) (image.Image, error) {
var dst_image image.Image
rect := src_image.Bounds()
width := rect.Dx()
height := rect.Dy()
colorModel := src_image.ColorModel()
// 今のところ RGBA, YCbCr のみ対応
if (colorModel != color.YCbCrModel) && (colorModel != color.RGBAModel) {
return nil, fmt.Errorf("ImageTransformByProfile: Unsupported ColorModel(%d)", colorModel)
}
var src_rgba *image.RGBA
var src_ycbcr *image.YCbCr
if colorModel == color.YCbCrModel {
// YCbCr の場合は RGB に変換する
src_ycbcr = src_image.(*image.YCbCr)
src_rgba = image.NewRGBA(rect)
DrawYCbCr(src_rgba, rect, src_ycbcr, image.Pt(0, 0))
} else {
src_rgba = src_image.(*image.RGBA) // type assertions
}
transform := CreateTransform(src_prof, DATA_RGBA_8, dst_prof, DATA_RGBA_8)
defer transform.DeleteTransform()
if transform == nil {
return nil, fmt.Errorf("ImageTransformByProfile: CreateTransform Failedl(%d)", colorModel)
}
dst_rgba := image.NewRGBA(rect)
src_pix := src_rgba.Pix
dst_pix := dst_rgba.Pix
len_pix := len(src_pix)
transform.DoTransform(src_pix, dst_pix, len_pix)
// YCbCr の場合は RGB から戻す
if colorModel == color.YCbCrModel {
dst_ycbcr := image.NewYCbCr(rect, src_ycbcr.SubsampleRatio)
var x int
var y int
for y = 0; y < height; y++ {
for x = 0; x < width; x++ {
r, g, b, _ := dst_rgba.At(x, y).RGBA()
yy, cb, cr := color.RGBToYCbCr(uint8(r), uint8(g), uint8(b))
yi := dst_ycbcr.YOffset(x, y)
ci := dst_ycbcr.COffset(x, y)
dst_ycbcr.Y[yi] = yy
dst_ycbcr.Cb[ci] = cb
dst_ycbcr.Cr[ci] = cr
}
}
dst_image = image.Image(dst_ycbcr)
} else {
dst_image = image.Image(dst_rgba)
}
return dst_image, nil
}
开发者ID:yoya,项目名称:go-qcms,代码行数:53,代码来源:image.go
示例3: Copy
// Copy copies the part of the source image defined by src and sr and writes to
// the part of the destination image defined by dst and the translation of sr
// so that sr.Min translates to dp.
func Copy(dst Image, dp image.Point, src image.Image, sr image.Rectangle, opts *Options) {
mask, mp, op := image.Image(nil), image.Point{}, Over
if opts != nil {
// TODO: set mask, mp and op.
}
dr := sr.Add(dp.Sub(sr.Min))
DrawMask(dst, dr, src, sr.Min, mask, mp, op)
}
开发者ID:nangong92t,项目名称:go_src,代码行数:11,代码来源:scale.go
示例4: testInterlacedFailWith
func testInterlacedFailWith(t *testing.T, rgb bool) {
src := readImage(t, "testdata/lenna.jpg")
dst := image.Image(image.NewYCbCr(image.Rect(0, 0, 640, 480), image.YCbCrSubsampleRatio420))
if rgb {
src = toRgb(src)
dst = toRgb(dst)
}
convert(t, dst, src, false, true, NewBicubicFilter())
convert(t, dst, src, true, true, NewBicubicFilter())
}
开发者ID:donlzx,项目名称:rez,代码行数:10,代码来源:resize_test.go
示例5: analyse
func analyse(settings CropSettings, img image.Image, cropWidth, cropHeight, realMinScale float64) (Crop, error) {
o := image.Image(image.NewRGBA(img.Bounds()))
now := time.Now()
edgeDetect(img, o)
log.Println("Time elapsed edge:", time.Since(now))
debugOutput(settings.DebugMode, &o, "edge")
now = time.Now()
if settings.FaceDetection {
err := faceDetect(settings, img, o)
if err != nil {
return Crop{}, err
}
log.Println("Time elapsed face:", time.Since(now))
debugOutput(settings.DebugMode, &o, "face")
} else {
skinDetect(img, o)
log.Println("Time elapsed skin:", time.Since(now))
debugOutput(settings.DebugMode, &o, "skin")
}
now = time.Now()
saturationDetect(img, o)
log.Println("Time elapsed sat:", time.Since(now))
debugOutput(settings.DebugMode, &o, "saturation")
now = time.Now()
var topCrop Crop
topScore := -1.0
cs := crops(o, cropWidth, cropHeight, realMinScale)
log.Println("Time elapsed crops:", time.Since(now), len(cs))
now = time.Now()
for _, crop := range cs {
nowIn := time.Now()
crop.Score = score(&o, &crop)
log.Println("Time elapsed single-score:", time.Since(nowIn))
if crop.Score.Total > topScore {
topCrop = crop
topScore = crop.Score.Total
}
}
log.Println("Time elapsed score:", time.Since(now))
if settings.DebugMode {
drawDebugCrop(&topCrop, &o)
debugOutput(true, &o, "final")
}
return topCrop, nil
}
开发者ID:dexter-cn,项目名称:smartcrop,代码行数:54,代码来源:crop.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng