Page 1 of 1

Returning imageData from NSImage?

Posted: Thu Aug 31, 2023 10:46 am
by Zax
Hello,

I'm new to Externals and I don't understand anything about objective-c stuff but I'm trying to get the icon of a MacOS Finder file to populate the imageData of a LC image control.

I built a script by copying bits found on the net but my problem concerns the final step: returning data that can be used by LC. I would like something like:

Code: Select all

set the imageData of image "MyImage" to MyExternal("/path to a file")
This is the end of my external script:

Code: Select all

put ObjC_NSBitmapImageRepRepresentationUsingType(tBitmapImageRep, 4, nothing) into tImageData // 4 for PNG
put DataFromNSData(tImageData) into dataResult // ???
return what ???

Code: Select all

private foreign handler ObjC_NSBitmapImageRepRepresentationUsingType(in pBitmapImageRep as ObjcId, in pType as CInt, in pProps as optional ObjcId) \
    returns ObjcId binds to "objc:NSBitmapImageRep.-representationUsingType:properties:"
Thank you for your help.

Re: Returning imageData from NSImage?

Posted: Wed Oct 11, 2023 8:33 am
by Zax
Thanks, I'll try as soon as I can :)

Re: Returning imageData from NSImage?

Posted: Mon Jul 01, 2024 11:17 pm
by PaulDaMacMan
I don't know what the OP was replying to in the second comment (seems to have been deleted), but my extension library here can do this (and the reverse, and a lot more): https://github.com/OpenXTalk-org/OXT_Ap ... ingLib.lcb
Specifically the handler's getIconForFile and setIconForFile.

Re: Returning imageData from NSImage?

Posted: Tue Jul 02, 2024 12:57 pm
by Zax
The message deleted by a moderator came from a bot: it proposed a “solution” as stupid as it was optimistic, as only bots know how to do. I don't have sufficient rights to delete my own answer.

Thanks for the link to your library, Paul. I'll take a closer look, and maybe ask you a few questions.

Re: Returning imageData from NSImage?

Posted: Tue Jul 02, 2024 1:59 pm
by PaulDaMacMan
Zax wrote:
Tue Jul 02, 2024 12:57 pm
The message deleted by a moderator came from a bot: it proposed a “solution” as stupid as it was optimistic, as only bots know how to do. I don't have sufficient rights to delete my own answer.

Thanks for the link to your library, Paul. I'll take a closer look, and maybe ask you a few questions.
Ah, OK, damn them bots!

There's also a couple of handlers in that library that help with Objective C stuff in general, so you can figure out what sort of NSObject an API may be returning (or it may not even an be an obj, could be a C primitives type or struct).
Sorry the code is kind of a mess with lots of lines commented out (there was lots of trial and error going on there).

Re: Returning imageData from NSImage?

Posted: Tue Jul 02, 2024 4:06 pm
by Zax
I have no problem accepting that bots can - often - offer somewhat stupid "solutions", but it annoys me when they try to reassure me with a jovial and optimistic tone by making me believe that my problem is solved with the few lines of code they provide me.
And they sent me a ton of comments: stupid code remains stupid code, even when explained.

Concerning NSImage, I will try - when I have enough time - to re-write one of my standalones which uses a Python graphics library with your external.