Since I can't recall any image library binding for nim which can read image file, write image file, resize image, and read pixel colors - correct me if I am wrong, and I don't think huge OpenCV is a good choice, I think maybe I could use GDIPlus on my windows 10 64bits.
khchen has supplied a binding as https://github.com/khchen/winim/blob/master/winim/inc/gdiplus.nim
the first step is initilization and exit.
proc GdiplusStartup*(token: ptr ULONG_PTR, input: ptr GdiplusStartupInput, output: ptr GdiplusStartupOutput): GpStatus {.winapi, stdcall, dynlib: "gdiplus", importc.}
proc GdiplusShutdown*(token: ULONG_PTR): VOID {.winapi, stdcall, dynlib: "gdiplus", importc.}
so I write the code
import winim
var
token: ULONG_PTR
input: GdiplusStartupInput
output: GdiplusStartupOutput
status: GpStatus
status = GdiplusStartup(&token, &input, &output)
echo status
which shows 17 which means UnsupportedGdiplusVersion according to https://docs.microsoft.com/en-us/windows/win32/api/gdiplustypes/ne-gdiplustypes-status
what is the problem?
then the following code gets wrong of cause
var img: ptr GpImage
status = GdipLoadImageFromFile(L"a.png", &img);
echo status
which says 18 ( GdiplusNotInitialized).I use gdiplus to deal image in wNim/wImage. You can look at it.
https://github.com/khchen/wNim/blob/master/wNim/private/wImage.nim
so bad, I met the similar problem stated in https://github.com/treeform/pixie/issues/503
I think it is better for me not to use https://github.com/treeform/pixie in real project at least for now, but take a glimpse from time to time.
I read something in https://github.com/khchen/wNim/blob/master/wNim/private/wImage.nim like
var
width1, height1, width2, height2: int32
then
if GdipGetImageWidth(gdipbmp1, cast[ptr UINT](&width1)) != Ok: return false
could it be better to write only int32 or UINT?
I know nothing about the underneath windows API since I am not a professional programmer, and for most of the time I use python.
[fileformats] 109,812
[fontformats] 85,772
[simd] 72,042
blends.nim 11,025
common.nim 2,987
contexts.nim 26,903
fonts.nim 23,257
images.nim 26,271
internal.nim 3,507
paints.nim 8,065
paths.nim 69,645
simd.nim 598
I think the answer is yes. The base type of UINT is int32 in winim. And the prototype of GdipGetImageWidth is:
proc GdipGetImageWidth*(image: ptr GpImage, width: ptr UINT): GpStatus
So following code should be work, too.
var width1: int32
if GdipGetImageWidth(gdipbmp1, &width1) != Ok: return false
I already forget why I add a cast here. Maybe width was int at first, so it needed the cast, and then I modified the int to int32 and forgot to remove the cast.