第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Golang 中將 GDI32.dll 位圖保存到磁盤

在 Golang 中將 GDI32.dll 位圖保存到磁盤

Go
白板的微信 2021-11-22 18:20:03
我的第一個 SO 問題 :-) 我希望通過調(diào)用 Windows 機(jī)器上的 User32.dll 和 GDI32.dll(項目要求)從 Golang 截取屏幕截圖。我有一個包含屏幕截圖像素的位圖的句柄。但是,我不知道如何訪問其數(shù)據(jù)或如何將其保存到磁盤。任何人都知道如何將 GDI 位圖映射到 Golang []byte 然后另存為 JPG 或 PNG?package mainimport "syscall"var (    user32            = syscall.NewLazyDLL("user32.dll")    procGetClientRect = user32.NewProc("GetClientRect")    // etc...    gdi32             = syscall.NewLazyDLL("gdi32.dll")    procCreateDC      = gdi32.NewProc("CreateDC")    SRCCOPY      uint = 13369376   //etc...)//// omitted for brevity//func TakeDesktopScreenshotViaWinAPI() {    // these are all calls to user32.dll or gdi32.dll    hDesktop := GetDesktopWindow()    desktopRect := GetClientRect(hDesktop)    width := int(desktopRect.Right - desktopRect.Left)    height := int(desktopRect.Bottom - desktopRect.Top)    // create device contexts    srcDC := GetDC(hDesktop)    targetDC := CreateCompatibleDC(srcDC)    // create bitmap to copy to    hBitmap := CreateCompatibleBitmap(targetDC, width, height)    // select the bitmap into target DC    hOldSelection := SelectObject(targetDC, HGDIOBJ(hBitmap))    //bit block transfer from src to target    BitBlt(targetDC, 0, 0, width, height, srcDC, 0, 0, SRCCOPY)   // how to save the  the data in   // *hBitmap ???   // restore selection   SelectObject(targetDC, hOldSelection)   // clean up   DeleteDC(HDC(targetDC))   ReleaseDC(hDesktop, srcDC)   DeleteObject(HGDIOBJ(hBitmap))}
查看完整描述

1 回答

?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗 獲得超3個贊

您可以使用vova616的屏幕截圖庫,或者查看screenshot_windows.go以了解所需的轉(zhuǎn)換方法。


根據(jù)提供的示例:


package main


import (

    "github.com/vova616/screenshot"

    "image/png"

    "os"

)


func main() {

    img, err := screenshot.CaptureScreen()

    if err != nil {

        panic(err)

    }

    f, err := os.Create("./ss.png")

    if err != nil {

        panic(err)

    }

    err = png.Encode(f, img)

    if err != nil {

        panic(err)

    }

    f.Close()

}


查看完整回答
反對 回復(fù) 2021-11-22
  • 1 回答
  • 0 關(guān)注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號