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


Golang C.SetImageInfoFilename函數代碼示例

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


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

示例1: NewFromFile

// NewFromFile loads a file at filename into a MagickImage.
// Exceptions are returned as MagickErrors.
func NewFromFile(filename string) (im *MagickImage, err error) {
	exception := C.AcquireExceptionInfo()
	defer C.DestroyExceptionInfo(exception)
	info := C.AcquireImageInfo()
	c_filename := C.CString(filename)
	defer C.free(unsafe.Pointer(c_filename))
	C.SetImageInfoFilename(info, c_filename)
	image := C.ReadImage(info, exception)
	if failed := C.CheckException(exception); failed == C.MagickTrue {
		C.DestroyImageInfo(info)
		return nil, ErrorFromExceptionInfo(exception)
	}
	return &MagickImage{Image: image, ImageInfo: info}, nil
}
開發者ID:mat,項目名稱:magick,代碼行數:16,代碼來源:magick.go

示例2: ToFile

// ToFile writes the (transformed) MagickImage to the regular file at filename. Magick determines
// the encoding of the output file by the extension given to the filename (e.g. "image.jpg", "image.png")
func (im *MagickImage) ToFile(filename string) (err error) {
	exception := C.AcquireExceptionInfo()
	defer C.DestroyExceptionInfo(exception)
	c_outpath := C.CString(filename)
	defer C.free(unsafe.Pointer(c_outpath))
	C.SetImageInfoFilename(im.ImageInfo, c_outpath)
	success := C.WriteImages(im.ImageInfo, im.Image, c_outpath, exception)
	if failed := C.CheckException(exception); failed == C.MagickTrue {
		return ErrorFromExceptionInfo(exception)
	}
	if success != C.MagickTrue {
		return &MagickError{"fatal", "", "could not write to " + filename + " for unknown reason"}
	}
	return nil
}
開發者ID:mat,項目名稱:magick,代碼行數:17,代碼來源:magick.go

示例3: ToBlob

// ToBlob takes a (transformed) MagickImage and returns a byte slice in the format you specify with extension.
// Magick uses the extension to transform the image in to the proper encoding (e.g. "jpg", "png")
func (im *MagickImage) ToBlob(extension string) (blob []byte, err error) {
	exception := C.AcquireExceptionInfo()
	defer C.DestroyExceptionInfo(exception)
	c_outpath := C.CString("image." + extension)
	defer C.free(unsafe.Pointer(c_outpath))
	C.SetImageInfoFilename(im.ImageInfo, c_outpath)
	var outlength (C.size_t)
	outblob := C.ImageToBlob(im.ImageInfo, im.Image, &outlength, exception)
	if failed := C.CheckException(exception); failed == C.MagickTrue {
		return nil, ErrorFromExceptionInfo(exception)
	}
	char_pointer := unsafe.Pointer(outblob)
	defer C.free(char_pointer)
	return C.GoBytes(char_pointer, (C.int)(outlength)), nil
}
開發者ID:mat,項目名稱:magick,代碼行數:17,代碼來源:magick.go

示例4: NewFromBlob

// NewFromBlob takes a byte slice of image data and an extension that defines the
// image type (e.g. "png", "jpg", etc). It loads the image data and returns a MagickImage.
// The extension is required so that Magick knows what processor to use.
func NewFromBlob(blob []byte, extension string) (im *MagickImage, err error) {
	if len(blob) < 1 {
		return nil, &MagickError{"fatal", "", "zero length blob passed to NewFromBlob"}
	}
	if len(extension) < 1 {
		return nil, &MagickError{"fatal", "", "zero length extension passed to NewFromBlob"}
	}
	exception := C.AcquireExceptionInfo()
	defer C.DestroyExceptionInfo(exception)
	info := C.AcquireImageInfo()
	defer C.DestroyImageInfo(info)
	c_filename := C.CString("image." + extension)
	defer C.free(unsafe.Pointer(c_filename))
	C.SetImageInfoFilename(info, c_filename)
	var success (C.MagickBooleanType)
	success = C.SetImageInfo(info, 1, exception)
	if success != C.MagickTrue {
		return nil, ErrorFromExceptionInfo(exception)
	}
	cloned_info := C.CloneImageInfo(info)
	success = C.GetBlobSupport(info)
	if success != C.MagickTrue {
		// No blob support, lets try reading from a file
		file, err := ioutil.TempFile("", "image."+extension)
		if _, err = file.Write(blob); err != nil {
			return nil, &MagickError{"fatal", "", "image format " + extension + " does not support blobs and could not write temp file"}
		}
		file.Close()
		return NewFromFile(file.Name())
	}
	length := (C.size_t)(len(blob))
	if length == 0 {
		return nil, &MagickError{"fatal", "", "empty blob"}
	}
	blob_start := unsafe.Pointer(&blob[0])
	image := C.ReadImageFromBlob(info, blob_start, length)

	if image == nil {
		return nil, &MagickError{"fatal", "", "corrupt image, not a " + extension}
	}

	if failed := C.CheckException(exception); failed == C.MagickTrue {
		return nil, ErrorFromExceptionInfo(exception)
	}

	return &MagickImage{Image: image, ImageInfo: cloned_info}, nil
}
開發者ID:mat,項目名稱:magick,代碼行數:50,代碼來源:magick.go


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