Discussion:
Problem: GdipDrawImageRectI vs GdipDrawImagePointRectI size mismatch
(too old to reply)
R.Wieser
2020-01-29 17:57:23 UTC
Permalink
Hello all,

I'm trying to draw a few images (onto another) using GDI+, and am runing
into a size-difference problem :

When I use GdipDrawImageRectI to draw a just-loaded image (with width and
height taken from the just-loaded image) it looks alright. However, when I
use GdipDrawImagePointRectI using the same image (again width and height
taken from it) its displayed larger as the first.

Again using GdipDrawImagePointRectI with a much larger image and using the
same width and height as the target image I'm left with something thats way
smaller thatn that target (It should have overwrittin the target completely,
instead there is a +/- 1/3 target size something in the top-left. It
simply doesn't make any sense. :-(

tl;dr:
GdipDrawImageRectI and GdipDrawImagePointRectI do not generate the same
results (when given the same arguments ofcourse).

Does anyone know whats going on here ?

Regards,
Rudy Wieser
Usenet Advocate #1337
2020-01-29 23:24:02 UTC
Permalink
I will say the Microsoft documentation is a very good resource on
understanding how EXACTLY a function works. Maybe your number conversion is
off? I looked at the function definitions and it looks like the two
functions accept a different type of x,y coordinate? GdipDrawImageRect seems
to accept the x and y values straight, while GdipDrawImagePointRectI seems
to accept x,y, and where it is on the screen, along with srcwidth/srcheight.
Try looking into this. In addition, if you don’t solve it, try changing the
values in where the rectangle is different. So yeah, just make sure the
arguments are right. Maybe GdipDrawImagePointRectI starts to draw from a
different place on the screen?

If all else fails, then just disassemble the function LOL....


"R.Wieser" wrote in message news:r0sh2m$ke2$***@gioia.aioe.org...

Hello all,

I'm trying to draw a few images (onto another) using GDI+, and am runing
into a size-difference problem :

When I use GdipDrawImageRectI to draw a just-loaded image (with width and
height taken from the just-loaded image) it looks alright. However, when I
use GdipDrawImagePointRectI using the same image (again width and height
taken from it) its displayed larger as the first.

Again using GdipDrawImagePointRectI with a much larger image and using the
same width and height as the target image I'm left with something thats way
smaller thatn that target (It should have overwrittin the target completely,
instead there is a +/- 1/3 target size something in the top-left. It
simply doesn't make any sense. :-(

tl;dr:
GdipDrawImageRectI and GdipDrawImagePointRectI do not generate the same
results (when given the same arguments ofcourse).

Does anyone know whats going on here ?

Regards,
Rudy Wieser
R.Wieser
2020-01-30 09:19:04 UTC
Permalink
Usenet Advocate #1337,
Post by Usenet Advocate #1337
I will say the Microsoft documentation is a very good resource on
understanding how EXACTLY a function works.
I've googled (and DDG-ed) for it, but have not found anything but a list in
which its arguments are named. Could you please post links to the pages
you found ? I'm in dire need of them.

In other words, an explanation how how it behaves is /exactly/ what I'm
missing. :-(
Post by Usenet Advocate #1337
GdipDrawImageRect seems to accept the x and y values straight, while
GdipDrawImagePointRectI seems to accept x,y, and where it is on the
screen, along with srcwidth/srcheight.
Yep, thats it in a nutshell. The whole question is, why/how is the
"srcwidth/srcheight" usage different from the "trgwidth/trgheight" used in
the first function ?

I take a 640x480 part from the source image using GdipDrawImagePointRectI
and place it on a 640x480 target image, expecting it to wholly cover the
target. It doesn't, not by a long shot. Why ?

Regards,
Rudy Wieser
Usenet Advocate #1337
2020-01-30 23:25:08 UTC
Permalink
OK, here is the links I found and used. It seems like both of those
functions just pass values into Graphics::DrawImage, but one of them seems
to be a long instead of an int, so make sure the conversing casting is
correct .. rectI takes an integer, while rect takes in a real. Are you
passing in integers number to both? Maybe place a hook on DrawImage and see
how the values are different (that’s some advanced debugging but I think
that’s a last step - I can probably try that myself over the weekend)

http://www.jose.it-berater.org/gdiplus/reference/flatapi/graphics/gdipdrawimagerecti.htm

http://www.jose.it-berater.org/gdiplus/reference/flatapi/graphics/gdipdrawimagerect.htm

https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-graphics-flat
(look for your functions)

https://docs.microsoft.com/en-us/windows/win32/api/gdiplusgraphics/nf-gdiplusgraphics-graphics-drawimage(inimage_inreal_inreal_inreal_inreal)?redirectedfrom=MSDN
(this is the actual function those two functions seem to call)

Maybe the source image isn't actually the size you want? Make sure nothing
happens to it when you switch functions. Also, try calling one without the
other. Maybe one of the functions make state changes you don't know about

Sorry, this is my first time on Usenet so I'm still figuring stuff out....


"R.Wieser" wrote in message news:r0u72u$jmq$***@gioia.aioe.org...

Usenet Advocate #1337,
Post by Usenet Advocate #1337
I will say the Microsoft documentation is a very good resource on
understanding how EXACTLY a function works.
I've googled (and DDG-ed) for it, but have not found anything but a list in
which its arguments are named. Could you please post links to the pages
you found ? I'm in dire need of them.

In other words, an explanation how how it behaves is /exactly/ what I'm
missing. :-(
Post by Usenet Advocate #1337
GdipDrawImageRect seems to accept the x and y values straight, while
GdipDrawImagePointRectI seems to accept x,y, and where it is on the
screen, along with srcwidth/srcheight.
Yep, thats it in a nutshell. The whole question is, why/how is the
"srcwidth/srcheight" usage different from the "trgwidth/trgheight" used in
the first function ?

I take a 640x480 part from the source image using GdipDrawImagePointRectI
and place it on a 640x480 target image, expecting it to wholly cover the
target. It doesn't, not by a long shot. Why ?

Regards,
Rudy Wieser
R.Wieser
2020-01-31 09:31:05 UTC
Permalink
Usenet Advocate #1337,
Post by Usenet Advocate #1337
OK, here is the links I found and used.
:-) Yes, those are the ones I found too.

While they /specify/ the argument types, they do not contain much, if
anything in regard to /describing/ them. :-(
Post by Usenet Advocate #1337
Maybe the source image isn't actually the size you want?
True. Its /much/ bigger than the target, so I wanted to copy a piece the
size of the target from it.

While the taken piece might well be exactly the size of the target, the
result doesn't cover the whole of that target (its way smaller).

Also remember I did a simpler test, trying to copy a smaller image into the
target, and found it to be of a different, /larger/ size than a similar
other function. In short, one result (way) smaller, another result (a bit)
larger.

I have no idea what could be causing either of that. :-(

... which is what this thread is all about.
Post by Usenet Advocate #1337
Maybe one of the functions make state changes you don't know about
:-) I don't know. But whatever it is, it isn't described in the links you
and I found. :-((
Post by Usenet Advocate #1337
Also, try calling one without the other.
I did, and after that also changed the order of them to see if it they would
perhaps be influencing each other. I did not see any change.
Post by Usenet Advocate #1337
Sorry, this is my first time on Usenet so I'm still figuring stuff out....
You're doing just fine, giving sensible responses.

Regards,
Rudy Wieser

P.s.
I found that the "GdipDrawImageRectRectI( )" function does what I want from
it. Still would like to know why that "GdipDrawImagePointRectI( )" one
works the way it does. Currently I can't use it as I can't predict the
result. :-\
Usenet Advocate #1337
2020-02-01 02:41:50 UTC
Permalink
I just tried using these functions in a sample program today and got the
same results you have...

I think I know your problem. GdipDrawImagePointRectI explicitly sets the
unit size as "UnitPixel", meaning the width/height coords are in units of 1
pixels

It seems as if GdipDrawImagePointRectI "scales" the srcwidth/srcheight
values you give to the function to make it smaller or larger relative to the
rectangle. First, It converts whatever unit you supply into pixels,

then it seems to multiply your srcwidth by the ratio of the graphics x
resolution (can be obtained by GetDpiX) over by the image x value (IDK how
to get this value)

and your srcheight is multiplied by the ratio of the graphics (windows) y
value (can be obtained by GetDpiY) over the image y value (I don’t know how
to get this)

I heard there is a DrawImage that will take in all the arguments of
GdipDrawImagePointRectI but will not scale your function, I will look into
it tomorrow along with my further developments. I had a very long day today
:)

The ReactOS code is very helpful.....

https://doxygen.reactos.org/d5/dee/dll_2win32_2gdiplus_2graphics_8c.html#a72a7544a72d57ce49bf5b67619b96902
https://doxygen.reactos.org/d1/d07/gdiplus__private_8h_source.html#l00354

"R.Wieser" wrote in message news:r10s5d$1ioc$***@gioia.aioe.org...

Usenet Advocate #1337,
Post by Usenet Advocate #1337
OK, here is the links I found and used.
:-) Yes, those are the ones I found too.

While they /specify/ the argument types, they do not contain much, if
anything in regard to /describing/ them. :-(
Post by Usenet Advocate #1337
Maybe the source image isn't actually the size you want?
True. Its /much/ bigger than the target, so I wanted to copy a piece the
size of the target from it.

While the taken piece might well be exactly the size of the target, the
result doesn't cover the whole of that target (its way smaller).

Also remember I did a simpler test, trying to copy a smaller image into the
target, and found it to be of a different, /larger/ size than a similar
other function. In short, one result (way) smaller, another result (a bit)
larger.

I have no idea what could be causing either of that. :-(

... which is what this thread is all about.
Post by Usenet Advocate #1337
Maybe one of the functions make state changes you don't know about
:-) I don't know. But whatever it is, it isn't described in the links you
and I found. :-((
Post by Usenet Advocate #1337
Also, try calling one without the other.
I did, and after that also changed the order of them to see if it they would
perhaps be influencing each other. I did not see any change.
Post by Usenet Advocate #1337
Sorry, this is my first time on Usenet so I'm still figuring stuff out....
You're doing just fine, giving sensible responses.

Regards,
Rudy Wieser

P.s.
I found that the "GdipDrawImageRectRectI( )" function does what I want from
it. Still would like to know why that "GdipDrawImagePointRectI( )" one
works the way it does. Currently I can't use it as I can't predict the
result. :-\
R.Wieser
2020-02-01 15:39:29 UTC
Permalink
Usenet Advocate #1337,
Post by Usenet Advocate #1337
then it seems to multiply your srcwidth by the ratio of the graphics x
resolution (can be obtained by GetDpiX) over by the image x value (IDK how
to get this value)
I thought that I had tried that (changing the DPI values in a source image
using an hex editor), but I must have missed the actually used value (though
the by "properties" displayed value did change).

I simply changed the horizontal and vertical DPI of the target by using
GdipBitmapSetResolution( ), and saw the size of the by
GdipDrawImagePointRectI( ) drawn image change as a result. When I than set
the H/V DPI of the target to the same as that of the source (300, 300) the
drawn 640x480 part exactly matched the 640x480 target image. Re-trying it
with the smaller image (dpi 75,75) caused the result to be the same as that
of the GdipDrawImageRectO( ) function.

In short, your above "that must be it" seems to be correct, the resulting
size depends on the DPI ratio between the target and source. Thanks. :-)

Blimy, it should have taken all but two lines of information in the
description of the GdipDrawImagePointRectI( ) function. :-(

Regards,
Rudy Wieser

Loading...