News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

gdiplus tests

Started by zedd151, March 12, 2025, 02:18:44 AM

Previous topic - Next topic

zedd151

Quote from: TimoVJL on March 12, 2025, 01:34:34 PMWhen object goes out of scope in OOP language, it will be destroyed after that.

So if object is created with GdipCreateFromHDC() in WM_PAINT, it should be destroyed with GdipDeleteGraphics() after it isn't needed anymore.

After the drawing has taken place, I would assume. Thanks Timo. Some things in MS documentation aren't always very clear.

Later:
Bbbbut wait a minute, I am not using GdipCreateFromHDC... did you look at my source code in post #1? I was following various gdiplus examples with bits and pieces from here and there... until I got everything working....
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

TimoVJL

Quote from: zedd151 on March 12, 2025, 01:42:48 PMLater:
Bbbbut wait a minute, I am not using GdipCreateFromHDC... did you look at my source code in post #1? I was following various gdiplus examples with bits and pieces from here and there... until I got everything working....
That GdipCreateFromHDC thing started at post #2
May the source be with you

zedd151

Quote from: TimoVJL on March 12, 2025, 02:23:31 PMThat GdipCreateFromHDC thing started at post #2
Ah, okay. That was meant for NoCforMe.... you should have been more specific.  :smiley:

Since you posted right after one of my posts, it appeared to me that your post was meant for me.
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

NoCforMe

Quote from: TimoVJL on March 12, 2025, 01:34:34 PMWhen object goes out of scope in OOP language, it will be destroyed after that.

So if object is created with GdipCreateFromHDC() in WM_PAINT, it should be destroyed with GdipDeleteGraphics() after it isn't needed anymore.
OK. But what about this other function, GdipDisposeImage(): when (and why) is it needed?

What does it mean to "dispose" [of] an image?
Assembly language programming should be fun. That's why I do it.

NoCforMe

Well, a partial answer, anyhow, from good old Stack Overflow:
QuoteThat being said, GdipCreateBitmapFromHBITMAP() returns a pointer to a GpBitmap object (which is wrapped by the Bitmap class in C++). GdipDisposeImage() is the correct way to release that object (which is called by the Image destructor in C++).

So it may not be needed here, since we're not creating a GpBitmap object using GdipCreateBitmapFromHBITMAP().

God damn, this shit be complicated ... too complicated ...
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on March 12, 2025, 02:40:12 PMOK. But what about this other function, GdipDisposeImage(): when (and why) is it needed?
I think it has to do with how HBITMAP is created. Heres mine.

        fn GdipCreateBitmapFromFile, addr upicname, addr gdipBmp        ; open image file, create image object
        invoke GdipCreateHBITMAPFromBitmap, gdipBmp, addr hBmpgdip, 0  ; get HBITMAP, from image object
        invoke GdipDisposeImage, gdipBmp                                ; dispose image object

I use hBmpgdip (HBITMAP) from here in WM_PAINT to blit the image to DC with
Not sure still if I need to call GdipDeleteGraphics() by what Timo says...

It seems there are many ways to do very similar things with gdi+, and I understand none of them. Yet.  :eusa_boohoo:
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

NoCforMe

Yeah, it'd be nice to find some kind of tutorial or at least a better explanation of how all that shit works that's better than Micro$oft's documentation.

Too lazy to look for it at the moment ...
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on March 12, 2025, 02:58:13 PMYeah, it'd be nice to find some kind of tutorial...
Too lazy to look for it at the moment ...
I just did a quick forum search for both gdi+ and gdip...  Shoulda done that even before starting this topic.  :eusa_dance:
Seems there are a lot of topics covering gdi+/gdiplus..

Should be some good examples (hopefully not buggy code) somewhere here already.  :biggrin:
Maybe tomorrow, its late here.
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

sinsi

How to release an object created from GdipCreateBitmapFromHBITMAP?

QuoteThat being said, GdipCreateBitmapFromHBITMAP() returns a pointer to a GpBitmap object (which is wrapped by the Bitmap class in C++). GdipDisposeImage() is the correct way to release that object (which is called by the Image destructor in C++).

I would imagine it's like an interface - you ask for an object and it gives you a reference.
Once you've finished with it you release it.

zedd151

It might just be easier to take the approach that hutch did in masm64 SDK examples. Load the .jpg or other image file and set it into a static control, rather than using WM_PAINT explicitly to draw/blit/stretch it to DC.  :tongue:

I don't know if his code regarding gdiplus is totally kosher now, after all I have been reading about gdi+ throughout the day. I don't see any Delete apis called there for gdip objects, unless I missed it.

And I will say it before NoCforMe does... Classes schmlasses.  :biggrin:
They don't make things easy for an assembly programmer.
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

sinsi


zedd151

Yes, I have seen that while doing some research today. Thanks.
It's just that there seems to be several different paths to open and display .jpg, .png, .gif images. But nothing I have read yet, tells me which api should follow another in the code flow if that makes any sense.
The code I posted in the first post works, but I don't know if the gdiplus code flow is complete.

It's not like plain old gdi, where you can check Task Manager for gdi leaks, if I am not mistaken. Gdiplus might be leaking like a sieve.

I am very tired now. I'll get back to this tomorrow.
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

TimoVJL

May the source be with you

NoCforMe

Quote from: sinsi on March 12, 2025, 04:00:44 PMThis might have some items of interest

https://github.com/VFPX/Win32API/tree/master/libraries/gdiplus

Sorry, not sorry: that really doesn't help.
It's the same documentation of the GDI+ flat functions that I already have in a Windows help (.chm) file. All it does is give the function parameters and return values: it doesn't really explain what the function does in any detail. That's what we need here.
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: NoCforMe on March 12, 2025, 07:23:49 PMSorry, not sorry: that really doesn't help.
Did you look at any?

You asked the question earlier
Quote from: NoCforMe on March 12, 2025, 02:40:12 PMOK. But what about this other function, GdipDisposeImage(): when (and why) is it needed?


The link gives an answer as to why
QuoteDECLARE INTEGER GdipDisposeImage IN gdiplus;
    INTEGER img 
Parameters:
img [in] Identifies the Image created by GdipLoadImageFromFile, GdipLoadImageFromStream and other Image constructors.