本文整理汇总了Golang中github.com/janelia-flyem/dvid/dvid.Image.GetPNG方法的典型用法代码示例。如果您正苦于以下问题:Golang Image.GetPNG方法的具体用法?Golang Image.GetPNG怎么用?Golang Image.GetPNG使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/janelia-flyem/dvid/dvid.Image
的用法示例。
在下文中一共展示了Image.GetPNG方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServeTile
// ServeTile returns a tile with appropriate Content-Type set.
func (d *Data) ServeTile(uuid dvid.UUID, ctx storage.Context, w http.ResponseWriter,
r *http.Request, parts []string) error {
if d.Levels == nil || len(d.Levels) == 0 {
return ErrNoMetadataSet
}
tileReq, err := d.parseTileReq(r, parts)
queryValues := r.URL.Query()
noblanksStr := dvid.InstanceName(queryValues.Get("noblanks"))
var noblanks bool
if noblanksStr == "true" {
noblanks = true
}
var formatStr string
if len(parts) >= 8 {
formatStr = parts[7]
}
data, err := d.getTileData(ctx, tileReq)
if err != nil {
server.BadRequest(w, r, err)
return err
}
if data == nil {
if noblanks {
http.NotFound(w, r)
return nil
}
img, err := d.getBlankTileImage(uuid, tileReq)
if err != nil {
return err
}
return dvid.WriteImageHttp(w, img, formatStr)
}
switch d.Encoding {
case LZ4:
var img dvid.Image
if err := img.Deserialize(data); err != nil {
return err
}
data, err = img.GetPNG()
w.Header().Set("Content-type", "image/png")
case PNG:
w.Header().Set("Content-type", "image/png")
case JPG:
w.Header().Set("Content-type", "image/jpeg")
}
if err != nil {
server.BadRequest(w, r, err)
return err
}
if _, err = w.Write(data); err != nil {
return err
}
return nil
}
示例2: ServeTile
// ServeTile returns a tile with appropriate Content-Type set.
func (d *Data) ServeTile(uuid dvid.UUID, ctx storage.Context, w http.ResponseWriter,
r *http.Request, parts []string) error {
if len(parts) < 7 {
return fmt.Errorf("'tile' request must be following by plane, scale level, and tile coordinate")
}
planeStr, scalingStr, coordStr := parts[4], parts[5], parts[6]
queryValues := r.URL.Query()
noblanksStr := dvid.InstanceName(queryValues.Get("noblanks"))
var noblanks bool
if noblanksStr == "true" {
noblanks = true
}
var formatStr string
if len(parts) >= 8 {
formatStr = parts[7]
}
// Construct the index for this tile
plane := dvid.DataShapeString(planeStr)
shape, err := plane.DataShape()
if err != nil {
err = fmt.Errorf("Illegal tile plane: %s (%v)", planeStr, err)
server.BadRequest(w, r, err)
return err
}
scaling, err := strconv.ParseUint(scalingStr, 10, 8)
if err != nil {
err = fmt.Errorf("Illegal tile scale: %s (%v)", scalingStr, err)
server.BadRequest(w, r, err)
return err
}
tileCoord, err := dvid.StringToPoint(coordStr, "_")
if err != nil {
err = fmt.Errorf("Illegal tile coordinate: %s (%v)", coordStr, err)
server.BadRequest(w, r, err)
return err
}
if tileCoord.NumDims() != 3 {
err = fmt.Errorf("Expected 3d tile coordinate, got %s", coordStr)
server.BadRequest(w, r, err)
return err
}
indexZYX := dvid.IndexZYX{tileCoord.Value(0), tileCoord.Value(1), tileCoord.Value(2)}
data, err := d.getTileData(ctx, shape, Scaling(scaling), indexZYX)
if err != nil {
server.BadRequest(w, r, err)
return err
}
if data == nil {
if noblanks {
http.NotFound(w, r)
return nil
}
img, err := d.getBlankTileImage(uuid, shape, Scaling(scaling))
if err != nil {
return err
}
return dvid.WriteImageHttp(w, img, formatStr)
}
switch d.Encoding {
case LZ4:
var img dvid.Image
if err := img.Deserialize(data); err != nil {
return err
}
data, err = img.GetPNG()
w.Header().Set("Content-type", "image/png")
case PNG:
w.Header().Set("Content-type", "image/png")
case JPG:
w.Header().Set("Content-type", "image/jpeg")
}
if err != nil {
server.BadRequest(w, r, err)
return err
}
if _, err = w.Write(data); err != nil {
return err
}
return nil
}