Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Convert NSImage to FireMonkey TBitmap

 Post Reply Post Reply
Author
Shalabi Nader View Drop Down
New Member
New Member
Avatar

Joined: 18 Jun 2014
Posts: 28
Post Options Post Options   Quote Shalabi Nader Quote  Post ReplyReply Direct Link To This Post Topic: Convert NSImage to FireMonkey TBitmap
    Posted: 13 Oct 2015 at 5:28pm
Hello,

I am building a Mac OS X Application, but facing a small problem, not related to mCL actually, but do any one knows how to convert an NSImage to a FireMonkey Bitmap, I am receiving this NSImage from Objective C API.

Many thanks,
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3259
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 14 Oct 2015 at 8:38am
Hi, 

In mCL, specifically the FMX.TMSNativeNSBaseControl unit, there is a function that converts the NSImage to a TBitmap: function BitmapFromImage(AImage: NSImage): TBitmap;

Kind Regards, 
Pieter
Back to Top
Shalabi Nader View Drop Down
New Member
New Member
Avatar

Joined: 18 Jun 2014
Posts: 28
Post Options Post Options   Quote Shalabi Nader Quote  Post ReplyReply Direct Link To This Post Posted: 14 Oct 2015 at 1:30pm
Thank you for your reply, I actually asked this question on Stackoverflow:
http://stackoverflow.com/questions/33092942/how-to-convert-nsimage-to-firemonkey-tbitmap, can I have your permission to add the code there (Highlighting your contribution) or if you like you can post it there yourself.

Thanks
Back to Top
Bruno Fierens View Drop Down
TMS Support
TMS Support
Avatar

Joined: 11 May 2010
Posts: 7900
Post Options Post Options   Quote Bruno Fierens Quote  Post ReplyReply Direct Link To This Post Posted: 14 Oct 2015 at 1:41pm
Sorry, the mCL license does not permit this.
Back to Top
Shalabi Nader View Drop Down
New Member
New Member
Avatar

Joined: 18 Jun 2014
Posts: 28
Post Options Post Options   Quote Shalabi Nader Quote  Post ReplyReply Direct Link To This Post Posted: 14 Oct 2015 at 1:44pm
Hi,

I tried the code, in PAServer terminal, I received the following message:
This application is assuming that a particular image contains an NSBitmapImageRep, which is not a good assumption. We are instantiating a bitmap so that whatever this is keeps working, but please do not do this. Break on void _NSPrivateIconImageRepSubclassAssumedToBeBitmap() to debug. This will be logged only once. This may break in the future.

I assume this is being accounted for in the series of "if Assigned"checks...

Regards,
Nader
Back to Top
Shalabi Nader View Drop Down
New Member
New Member
Avatar

Joined: 18 Jun 2014
Posts: 28
Post Options Post Options   Quote Shalabi Nader Quote  Post ReplyReply Direct Link To This Post Posted: 14 Oct 2015 at 1:50pm
Originally posted by Bruno Fierens

Sorry, the mCL license does not permit this.

No worries, thank you for your feedback, I do appreciate it.

Regards,
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3259
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 14 Oct 2015 at 2:59pm
Hi, 

This code originates from an older iOS version, and it could be deprecated in a future iOS version, but we haven't found a valid solution to transfer an NSImage to a TBitmap. Whenever the NSBitmapImageRep breaks, the code should be safe as it checks for assignments. As soon as we have found a solution, we will replace the current code.

Kind Regards, 
Pieter


Back to Top
Shalabi Nader View Drop Down
New Member
New Member
Avatar

Joined: 18 Jun 2014
Posts: 28
Post Options Post Options   Quote Shalabi Nader Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jul 2016 at 8:46pm
Any update on this...
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3259
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jul 2016 at 9:07pm
Sorry, we still haven't found a workaround to ignore this warning, but the code is still valid.
Back to Top
Shalabi Nader View Drop Down
New Member
New Member
Avatar

Joined: 18 Jun 2014
Posts: 28
Post Options Post Options   Quote Shalabi Nader Quote  Post ReplyReply Direct Link To This Post Posted: 31 Jul 2016 at 4:32pm
Yes, I understand the code is valid from a "safety" perspective, but it is not working :)
I previously posted this question on stackoverflow, would you kindly check it:
http://stackoverflow.com/questions/33092942/how-to-convert-nsimage-to-firemonkey-tbitmap

Regards
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3259
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 01 Aug 2016 at 9:33am
We have invesigated this further and changed the conversion routine, converting the original NSImage to a NSData via the TIFFRepresentation function. The next version will have this included.
Back to Top
Shalabi Nader View Drop Down
New Member
New Member
Avatar

Joined: 18 Jun 2014
Posts: 28
Post Options Post Options   Quote Shalabi Nader Quote  Post ReplyReply Direct Link To This Post Posted: 02 Aug 2016 at 7:03am
Awesome!!!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down