iseahound / ImagePut

A core library for images in AutoHotkey. Supports AutoHotkey v1 and v2.
https://www.autohotkey.com/boards/viewtopic.php?f=83&t=76633
MIT License
116 stars 24 forks source link

Puzzled in pBitmap, hBitmap and BitmapBuffer #22

Closed hyaray closed 1 month ago

hyaray commented 1 year ago

what I know is: use pBitmap: has source from rect of screent, file, clipboard and so on, use hBitmap : no clear source, create by CreateDIBSection pBitmap and hBitmap can covert to each other.

I see BitmapBuffer in your code, why use this? put_window use CreateWindowEx instead of gui. too much doubt...

BTW, I write a funtion for crop to get new postion by width, fyi ^_^

;v<0          width - abs(v)
;v<1          width * v
;v<width   v
;v≥width   other
forCrop(width, v, other:=0) {
    if (v == 0)
        return v
    if (v < 0) {
        v := width - abs(v)
        if (v < 0)
            v := other
    } else if (v < 1) {
        v := round(width * v)
    } else if (v > width) {
        v := other
    }
    return v
}
iseahound commented 1 year ago

Hi, thanks for taking a look though the code.

The main difference is that hBitmap is used by GDI and pBitmap is used by GDI+. However, you do not have access to the pixels with both hBitmap and pBitmap. Therefore, I created BitmapBuffer to help users who want access to pixels.

Initially, I thought that just returning a buffer with the pixel data was good enough. However, I realized that people would have trouble running pixelsearch and imagesearch, so I wrote the machine code to help them.

You should only use BitmapBuffer if you need access to pixels. Otherwise it is much faster to use either hBitmap or pBitmap.