當前位置: 首頁>>代碼示例>>Golang>>正文


Golang png.DecodeConfig函數代碼示例

本文整理匯總了Golang中image/png.DecodeConfig函數的典型用法代碼示例。如果您正苦於以下問題:Golang DecodeConfig函數的具體用法?Golang DecodeConfig怎麽用?Golang DecodeConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了DecodeConfig函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CountColor

func CountColor(_png io.Reader) int {
	/* modify here */
	config, err := png.DecodeConfig(_png)
	if err != nil {
		log.Fatal(err)
	}

	width := config.Width * 10
	height := config.Height * 10

	_png = GetPngBinary()

	img, err := png.Decode(_png)
	if err != nil {
		log.Fatal(err)
	}

	var r, g, b, a uint32
	var str string
	m := make(map[string]int)
	for x := 0; x < width; x++ {
		for y := 0; y < height; y++ {

			r, g, b, a = img.At(x, y).RGBA()
			str = strconv.Itoa(int(r)) + strconv.Itoa(int(g)) + strconv.Itoa(int(b)) + strconv.Itoa(int(a))
			m[str] = 1
		}
	}

	return len(m - 1)
}
開發者ID:takkaw,項目名稱:gdd2011_golang,代碼行數:31,代碼來源:png.go

示例2: DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error) {
	var (
		d   decoder
		cfg image.Config
		err error
	)
	if err = d.decodeHeader(r); err != nil {
		return cfg, err
	}
	if err = d.decodeEntries(r); err != nil {
		return cfg, err
	}
	e := d.entries[0]
	buf := make([]byte, e.Size+14)
	n, err := io.ReadFull(r, buf[14:])
	if err != nil && err != io.ErrUnexpectedEOF {
		return cfg, err
	}
	buf = buf[:14+n]
	if n > 8 && bytes.Compare(buf[14:22], pngHeader) == 0 {
		return png.DecodeConfig(bytes.NewReader(buf[14:]))
	}

	d.forgeBMPHead(buf, &e)
	return bmp.DecodeConfig(bytes.NewReader(buf))
}
開發者ID:zyxar,項目名稱:goico,代碼行數:26,代碼來源:reader.go

示例3: parsePNG

func parsePNG(r io.Reader) (int, int, error) {
	cfg, err := png.DecodeConfig(r)
	if err != nil {
		return 0, 0, err
	}

	return cfg.Width, cfg.Height, nil
}
開發者ID:coscms,項目名稱:go-imgparse,代碼行數:8,代碼來源:png.go

示例4: assertSprite

func (s *testService) assertSprite(path string, width, height int) {
	buf := s.sprites[path]
	Ω(buf).ShouldNot(BeNil())
	config, err := png.DecodeConfig(bytes.NewReader(buf.Bytes()))
	Ω(err).Should(Succeed())
	Ω(config.Width).Should(Equal(width))
	Ω(config.Height).Should(Equal(height))
}
開發者ID:redforks,項目名稱:css,代碼行數:8,代碼來源:spriter_test.go

示例5: PngDecodeConfigFromFile

func PngDecodeConfigFromFile(path string) (conf image.Config, err error) {
	file, err := os.Open(path)
	if err != nil {
		return
	}
	defer file.Close()
	return png.DecodeConfig(file)
}
開發者ID:keysonZZZ,項目名稱:kmg,代碼行數:8,代碼來源:png.go

示例6: main

func main() {

	width := 1200.0
	height := 200.0

	flag.Parse()
	canvas.Start(width, height)
	canvas.Title("Planets")
	canvas.Rect(0, 0, width, height, "fill:black")
	nobj := len(ssDist)
	y := height / 2.0
	margin := 100.0
	minsize := 7.0
	labeloc := height / 4.0

	var x, r, imScale, maxh float64
	var px, po float64

	if *showdisk {
		maxh = float64(height) / minsize
	} else {
		maxh = float64(height) / 4.0
	}
	for i := 1; i < int(nobj); i++ {
		x = vmap(ssDist[i], ssDist[1.0], ssDist[nobj-1.0], float64(margin), float64(width-margin))
		r = (vmap(ssRad[i], ssRad[1.0], ssRad[nobj-1.0], minsize, maxh)) / 2.0
		px = float64(x)
		if *showdisk {
			po = 0.0
			canvas.Circle(px, y, float64(r), "fill:#"+ssColor[i])
		} else { // show images
			f, err := os.Open(ssImages[i])
			if err != nil {
				println("bad image file:", ssImages[i])
				continue
			}
			defer f.Close()
			p, perr := png.DecodeConfig(f)
			if perr != nil {
				println("bad decode:", ssImages[i])
				continue
			}
			imScale = r / float64(p.Width)
			hs := float64(p.Height) * imScale
			dy := y - (float64(hs) / 2.0) // center the image
			po = float64(r) / 2.0
			canvas.Image(px, dy, float64(r), float64(hs), ssImages[i])
		}
		if ssDist[i] == 1.0 { // earth
			canvas.Line(px+po, y-po, px+po, y-labeloc,
				"stroke-width:1px;stroke:white")
			canvas.Text(px+po, y-labeloc-10, "You are here",
				"fill:white; font-size:14px; font-family:Calibri; text-anchor:middle")
		}
	}
	canvas.End()
}
開發者ID:stanim,項目名稱:svgof,代碼行數:57,代碼來源:planets.go

示例7: main

func main() {
	flag.Parse()
	width, height := *cw, *ch
	tfmt := "fill:white; font-size:%dpx; font-family:Calibri,sans; text-anchor:middle"
	canvas.Start(width, height)
	canvas.Title("Planets")
	canvas.Rect(0, 0, width, height, "fill:black")
	nobj := len(ssDist)
	y := height / 2
	margin := 100
	minsize := 7.0
	labeloc := height / 4
	fontsize := (width * 20) / 1000

	var x, r, imScale, maxh float64
	var px, po int

	if *showdisk {
		maxh = float64(height) / minsize
	} else {
		maxh = float64(height) / 4.0
	}
	for i := 1; i < nobj; i++ {
		x = vmap(ssDist[i], ssDist[1], ssDist[nobj-1], float64(margin), float64(width-margin))
		r = (vmap(ssRad[i], ssRad[1], ssRad[nobj-1], minsize, maxh)) / 2
		px = int(x)
		if *showdisk {
			po = 0
			canvas.Circle(px, y, int(r), "fill:#"+ssColor[i])
		} else { // show images
			f, err := os.Open(ssImages[i])
			if err != nil {
				fmt.Fprintf(os.Stderr, "%s: %s\n", err, ssImages[i])
				continue
			}
			defer f.Close()
			p, perr := png.DecodeConfig(f)
			if perr != nil {
				fmt.Fprintf(os.Stderr, "%s: %s\n", perr, ssImages[i])
				continue
			}
			imScale = r / float64(p.Width)
			hs := float64(p.Height) * imScale
			dy := y - (int(hs) / 2) // center the image
			po = int(r) / 2
			canvas.Image(px, dy, int(r), int(hs), ssImages[i])
		}
		if ssDist[i] == 1.0 && *showyou { // earth
			canvas.Line(px+po, y-po, px+po, y-labeloc,
				"stroke-width:1px;stroke:white")
			canvas.Text(px+po, y-labeloc-10, "You are here", fmt.Sprintf(tfmt, fontsize))
		}
	}
	canvas.End()
}
開發者ID:Ribosome2,項目名稱:svgo,代碼行數:55,代碼來源:planets.go

示例8: main

func main() {

	width := 1300
	height := 200

	flag.Parse()
	canvas.Start(width, height)
	canvas.Title("Planets")
	canvas.Rect(0, 0, width, height, "fill:black")
	canvas.Gstyle("stroke:none")
	nobj := len(ssDist)
	y := height / 2
	margin := 100
	minsize := 7.0
	labeloc := height / 4

	var x, r, imScale, maxh float64

	if *showimages {
		maxh = float64(height) / 4.0
	} else {
		maxh = float64(height) / minsize
	}

	for i := 1; i < nobj; i++ {
		x = vmap(ssDist[i], ssDist[1], ssDist[nobj-1], float64(margin), float64(width-margin))
		r = (vmap(ssRad[i], ssRad[1], ssRad[nobj-1], minsize, maxh)) / 2
		if *showimages {
			f, err := os.Open(ssImages[i])
			defer f.Close()
			if err != nil {
				continue
			}
			p, perr := png.DecodeConfig(f)
			if perr != nil {
				continue
			}
			imScale = r / float64(p.Width)
			hs := float64(p.Height) * imScale
			dy := y - (int(hs) / 2) // center the image
			canvas.Image(int(x), dy, int(r), int(hs), ssImages[i])
		} else {
			canvas.Circle(int(x), int(y), int(r), "fill:#"+ssColor[i])
		}
		if ssDist[i] == 1.0 { // earth
			canvas.Line(int(x), int(y), int(x), int(y)-labeloc, "stroke:white")
			canvas.Text(int(x), int(y)-labeloc-10, "You are here", "fill:white; font-size:14; font-family:Calibri; text-anchor:middle")
		}
	}
	canvas.Gend()
	canvas.End()
}
開發者ID:krasin,項目名稱:svgo,代碼行數:52,代碼來源:planets.go

示例9: getImageDimension

func getImageDimension(imagePath string) (int, int) {
	file, err := os.Open(imagePath)
	if err != nil {
		fmt.Printf("Cannot get image size #1\n")
		return 0, 0
	}
	defer file.Close()
	image, err := png.DecodeConfig(file)
	if err != nil {
		fmt.Printf("Cannot get image size #2: %s\n", err.Error())
		return 0, 0
	}
	return image.Width, image.Height
}
開發者ID:APXEOLOG,項目名稱:hafen-map-tool,代碼行數:14,代碼來源:map-merger.go

示例10: validPNGFile

func validPNGFile(fn string) bool {
	pngImage, err := os.Open(fn)

	check(err)

	defer pngImage.Close()

	_, err = png.DecodeConfig(pngImage)

	if err != nil {
		return false
	}

	return true
}
開發者ID:peterhellberg,項目名稱:tinypng,代碼行數:15,代碼來源:main.go

示例11: decodePNG

func decodePNG(f multipart.File) (*Image, error) {
	var image Image

	ic, err := png.DecodeConfig(f)
	_, err = f.Seek(0, 0)
	i, err := png.Decode(f)

	if err != nil {
		return nil, fmt.Errorf("Could not decode PNG file.")
	}

	image.Config = ic
	image.Image = i

	return &image, nil
}
開發者ID:danhardman,項目名稱:image-to-table,代碼行數:16,代碼來源:app.go

示例12: Example_body

func Example_body() {
	cmd := exec.Command("./cdc", "body", "-addr", "2684420101", "../../testcache")

	output := new(bytes.Buffer)
	cmd.Stdout = output

	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}

	config, err := png.DecodeConfig(output)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("PNG image data, %d x %d\n", config.Width, config.Height)
	// Output:
	// PNG image data, 83 x 120
}
開發者ID:schorlet,項目名稱:cdc,代碼行數:18,代碼來源:example_test.go

示例13: visit

func visit(path string, f os.FileInfo, err error) error {
	i, ierr := os.Open(path)
	defer i.Close()
	if ierr != nil {
		return err
	}

	// check if file jpg or png
	// get dimensions of images
	// lowres images to other directory and highres to another

	switch strings.ToLower(filepath.Ext(path)) {

	case ".jpg", ".jpeg":
		j, jerr := jpeg.DecodeConfig(i)
		i.Close()
		if jerr != nil {
			return jerr
		}
		v, fname := validateResolution(j), f.Name()
		err := move(path, fname, v)
		if err != nil {
			fmt.Println(err)
		}
		return nil

	case ".png":
		p, perr := png.DecodeConfig(i)
		i.Close()
		if perr != nil {
			return perr
		}
		v, fname := validateResolution(p), f.Name()
		err := move(path, fname, v)
		if err != nil {
			fmt.Println(err)
		}
		return nil
	}

	return nil
}
開發者ID:jozan,項目名稱:wpsorter,代碼行數:42,代碼來源:wpsorter.go

示例14: Example

// Example gets an entry from the cache and prints to stdout.
func Example() {
	cache, err := cdc.OpenCache("testcache")
	if err != nil {
		log.Fatal(err)
	}

	entry, err := cache.OpenURL("https://golang.org/doc/gopher/pkg.png")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(entry.URL())

	header, err := entry.Header()
	if err != nil {
		log.Fatal(err)
	}
	for _, key := range []string{"Status", "Content-Length", "Content-Type"} {
		fmt.Printf("%s: %s\n", key, header.Get(key))
	}

	body, err := entry.Body()
	if err != nil {
		log.Fatal(err)
	}
	defer body.Close()

	config, err := png.DecodeConfig(body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("PNG image data, %d x %d\n", config.Width, config.Height)

	// Output:
	// https://golang.org/doc/gopher/pkg.png
	// Status: 200
	// Content-Length: 5409
	// Content-Type: image/png
	// PNG image data, 83 x 120
}
開發者ID:schorlet,項目名稱:cdc,代碼行數:40,代碼來源:example_test.go

示例15: Dimensions

func (this *UploadedFile) Dimensions() (int, int, error) {
	f, err := os.Open(this.path)
	if err != nil {
		return 0, 0, err
	}

	var cfg image.Config
	switch true {
	case this.IsGif():
		cfg, err = gif.DecodeConfig(f)
	case this.IsPng():
		cfg, err = png.DecodeConfig(f)
	case this.IsJpeg():
		cfg, err = jpeg.DecodeConfig(f)
	default:
		return 0, 0, errors.New("Invalid mime type!")
	}

	if err != nil {
		return 0, 0, err
	}

	return cfg.Width, cfg.Height, nil
}
開發者ID:rizzles,項目名稱:convert,代碼行數:24,代碼來源:uploadedfile.go


注:本文中的image/png.DecodeConfig函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。