예제 #1
0
파일: bitmap.go 프로젝트: hoperuin/gform
func NewBitmapFromResource(instance w32.HINSTANCE, resName *uint16, resType *uint16, background Color) (*Bitmap, error) {
	var gpBitmap *uintptr
	var err error
	var hRes w32.HRSRC

	hRes, err = w32.FindResource(w32.HMODULE(instance), resName, resType)
	if err != nil {
		return nil, err
	}
	resSize := w32.SizeofResource(w32.HMODULE(instance), hRes)
	pResData := w32.LockResource(w32.LoadResource(w32.HMODULE(instance), hRes))
	resBuffer := w32.GlobalAlloc(w32.GMEM_MOVEABLE, resSize)
	pResBuffer := w32.GlobalLock(resBuffer)
	w32.MoveMemory(pResBuffer, pResData, resSize)

	stream := w32.CreateStreamOnHGlobal(resBuffer, false)

	gpBitmap, err = w32.GdipCreateBitmapFromStream(stream)
	if err != nil {
		return nil, err
	}
	defer stream.Release()
	defer w32.GlobalUnlock(resBuffer)
	defer w32.GlobalFree(resBuffer)
	defer w32.GdipDisposeImage(gpBitmap)

	var hbitmap w32.HBITMAP
	// Reverse gform.RGB to BGR to satisfy gdiplus color schema.
	hbitmap, err = w32.GdipCreateHBITMAPFromBitmap(gpBitmap, uint32(RGB(background.B(), background.G(), background.R())))
	if err != nil {
		return nil, err
	}

	return assembleBitmapFromHBITMAP(hbitmap)
}
예제 #2
0
파일: bitmap.go 프로젝트: hoperuin/gform
func NewBitmapFromFile(filepath string, background Color) (*Bitmap, error) {
	var gpBitmap *uintptr
	var err error

	gpBitmap, err = w32.GdipCreateBitmapFromFile(filepath)
	if err != nil {
		return nil, err
	}
	defer w32.GdipDisposeImage(gpBitmap)

	var hbitmap w32.HBITMAP
	// Reverse gform.RGB to BGR to satisfy gdiplus color schema.
	hbitmap, err = w32.GdipCreateHBITMAPFromBitmap(gpBitmap, uint32(RGB(background.B(), background.G(), background.R())))
	if err != nil {
		return nil, err
	}

	return assembleBitmapFromHBITMAP(hbitmap)
}