示例#1
0
func (this *Window) FlushImage(bounds ...image.Rectangle) {
	this.bufferback = NewDIB(this.buffer.Bounds())
	*this.bufferback = *this.buffer

	hdc := w32.GetDC(this.hwnd)
	this.blitImage(hdc, this.buffer)
	w32.DeleteDC(hdc)
}
示例#2
0
func (this *Window) FlushImage(bounds ...image.Rectangle) {
	if this.buffer.Bounds().Empty() {
		return // happens when window is minimised
	}
	this.bufferback = NewDIB(this.buffer.Bounds())
	*this.bufferback = *this.buffer

	hdc := w32.GetDC(this.hwnd)
	this.blitImage(hdc, this.buffer)
	w32.DeleteDC(hdc)
}
示例#3
0
func (this *Canvas) DrawBitmap(bmp *Bitmap, x, y int) {
	cdc := w32.CreateCompatibleDC(0)
	defer w32.DeleteDC(cdc)

	hbmpOld := w32.SelectObject(cdc, w32.HGDIOBJ(bmp.GetHBITMAP()))
	defer w32.SelectObject(cdc, w32.HGDIOBJ(hbmpOld))

	w, h := bmp.Size()

	w32.BitBlt(this.hdc, x, y, w, h, cdc, 0, 0, w32.SRCCOPY)
}
示例#4
0
func (this *Canvas) Dispose() {
	if !this.doNotDispose && this.hdc != 0 {
		if this.hwnd == 0 {
			w32.DeleteDC(this.hdc)
		} else {
			w32.ReleaseDC(this.hwnd, this.hdc)
		}

		this.hdc = 0
	}
}
示例#5
0
func (this *Canvas) DrawStretchedBitmap(bmp *Bitmap, rect *Rect) {
	cdc := w32.CreateCompatibleDC(0)
	defer w32.DeleteDC(cdc)

	hbmpOld := w32.SelectObject(cdc, w32.HGDIOBJ(bmp.GetHBITMAP()))
	defer w32.SelectObject(cdc, w32.HGDIOBJ(hbmpOld))

	w, h := bmp.Size()

	rc := rect.GetW32Rect()
	w32.StretchBlt(this.hdc, int(rc.Left), int(rc.Top), int(rc.Right), int(rc.Bottom), cdc, 0, 0, w, h, w32.SRCCOPY)
}
示例#6
0
func (this *Window) FlushImage(bounds ...image.Rectangle) {
	hdc := w32.GetDC(this.hwnd)
	this.blitImage(hdc)
	w32.DeleteDC(hdc)
}
示例#7
0
func (this *Window) Repaint() {
	hdc := w32.GetDC(this.hwnd)
	this.blitImage(hdc, this.bufferback)
	w32.DeleteDC(hdc)
}
func CaptureRect(rect image.Rectangle) (*image.RGBA, error) {
	hDC := w32.GetDC(0)
	if hDC == 0 {
		return nil, fmt.Errorf("Could not Get primary display err:%d.\n", w32.GetLastError())
	}
	defer w32.ReleaseDC(0, hDC)

	m_hDC := w32.CreateCompatibleDC(hDC)
	if m_hDC == 0 {
		return nil, fmt.Errorf("Could not Create Compatible DC err:%d.\n", w32.GetLastError())
	}
	defer w32.DeleteDC(m_hDC)

	x, y := rect.Dx(), rect.Dy()

	bt := w32.BITMAPINFO{}
	bt.BmiHeader.BiSize = uint(reflect.TypeOf(bt.BmiHeader).Size())
	bt.BmiHeader.BiWidth = x
	bt.BmiHeader.BiHeight = -y
	bt.BmiHeader.BiPlanes = 1
	bt.BmiHeader.BiBitCount = 32
	bt.BmiHeader.BiCompression = w32.BI_RGB

	ptr := unsafe.Pointer(uintptr(0))

	m_hBmp := w32.CreateDIBSection(m_hDC, &bt, w32.DIB_RGB_COLORS, &ptr, 0, 0)
	if m_hBmp == 0 {
		return nil, fmt.Errorf("Could not Create DIB Section err:%d.\n", w32.GetLastError())
	}
	if m_hBmp == w32.InvalidParameter {
		return nil, fmt.Errorf("One or more of the input parameters is invalid while calling CreateDIBSection.\n")
	}
	defer w32.DeleteObject(w32.HGDIOBJ(m_hBmp))

	obj := w32.SelectObject(m_hDC, w32.HGDIOBJ(m_hBmp))
	if obj == 0 {
		return nil, fmt.Errorf("error occurred and the selected object is not a region err:%d.\n", w32.GetLastError())
	}
	if obj == 0xffffffff { //GDI_ERROR
		return nil, fmt.Errorf("GDI_ERROR while calling SelectObject err:%d.\n", w32.GetLastError())
	}
	defer w32.DeleteObject(obj)

	//Note:BitBlt contains bad error handling, we will just assume it works and if it doesn't it will panic :x
	w32.BitBlt(m_hDC, 0, 0, x, y, hDC, rect.Min.X, rect.Min.Y, w32.SRCCOPY)

	var slice []byte
	hdrp := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
	hdrp.Data = uintptr(ptr)
	hdrp.Len = x * y * 4
	hdrp.Cap = x * y * 4

	imageBytes := make([]byte, len(slice))

	for i := 0; i < len(imageBytes); i += 4 {
		imageBytes[i], imageBytes[i+2], imageBytes[i+1], imageBytes[i+3] = slice[i+2], slice[i], slice[i+1], slice[i+3]
	}

	img := &image.RGBA{imageBytes, 4 * x, image.Rect(0, 0, x, y)}
	return img, nil
}