Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGImage missing ctor to create from NativeHandle/IntPtr #16314

Closed
Cheesebaron opened this issue Oct 11, 2022 · 5 comments
Closed

CGImage missing ctor to create from NativeHandle/IntPtr #16314

Cheesebaron opened this issue Oct 11, 2022 · 5 comments
Labels
need-attention An issue requires our attention/response

Comments

@Cheesebaron
Copy link

Steps to Reproduce

In Xamarin.iOS we can do new CGImage(intPtr) this is missing from net6.0-ios. I.e. we have some code generating thumbnails asynchronously:

void ImageReadyCallback(CMTime requestedTime, IntPtr imageRef, CMTime actualTime,
    AVAssetImageGeneratorResult result, NSError imageError)
{
    var image = new CGImage(imageRef);
    var skImage = image.ToSKBitmap();
    t.TrySetResult(skImage);
}

var handler = new AVAssetImageGeneratorCompletionHandler(ImageReadyCallback);

The callback in AVAssetImageGeneratorCompletionHandler still returns IntPtr, but there is no way to get a CGImage from it.

Expected Behavior

Some way to turn the IntPtr back into a CGImage

Actual Behavior

Ctor missing

Environment

Version information
Visual Studio Community 2022 for Mac
Version 17.3.6 (build 20)
Installation UUID: dd331937-eb2e-413a-9850-a08751dab655

Runtime
.NET 6.0.5 (64-bit)
Architecture: Arm64

Roslyn (Language Service)
4.3.0-3.22312.2+52adfb8b2dc71ed4278debcf13960f2116868608

NuGet
Version: 6.2.1.2

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/6.0.401/Sdks
SDK Versions:
	6.0.401
	6.0.400
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	6.0.9
	6.0.8

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin.Android
Version: 13.0.0.0 (Visual Studio Community)
Commit: xamarin-android/d17-3/030cd63
Android SDK: /Users/tomaszcielecki/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		12.1 (API level 32)
		12.0 (API level 31)
		10.0 (API level 29)
		13.0 (API level 33)
		7.0  (API level 24)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 33.0.2
SDK Build Tools Version: 33.0.0

Build Information: 
Mono: dffa5ab
Java.Interop: xamarin/java.interop/d17-3@7716ae53
SQLite: xamarin/sqlite/3.38.5@df4deab
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@14076a6

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.12
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.3.0.23
Hash: 965bf40
Branch: remotes/origin/d17-3
Build date: 2022-09-22 15.21.49 UTC

Android Device Manager
Version: 0.0.0.1169
Hash: fafb1d5
Branch: fafb1d5
Build date: 2022-09-22 15.21.49 UTC

Apple Developer Tools
Xcode 14.0.1 (21336)
Build 14A400

Xamarin.Mac
Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

Xamarin.iOS
Version: 16.0.0.72 (Visual Studio Community)
Hash: 6756a1146
Branch: release/6.0.4xx-xcode14
Build date: 2022-09-21 08:51:06-0400

Xamarin Designer
Version: 17.3.0.208
Hash: 0de472ea0
Branch: remotes/origin/d17-3
Build date: 2022-09-22 15.21.44 UTC

Build Information
Release ID: 1703060020
Git revision: f7a6334599543f127e737d6de1f362bbe36cebca
Build date: 2022-09-22 15:19:46+00
Build branch: release-17.3
Build lane: release-17.3

Operating System
Mac OS X 12.6.0
Darwin 21.6.0 Darwin Kernel Version 21.6.0
    Mon Aug 22 20:19:52 PDT 2022
    root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64

Installed Workload Ids      Manifest Version      Installation Source
---------------------------------------------------------------------
macos                       12.3.454/6.0.400      SDK 6.0.400
ios                         15.4.454/6.0.400      SDK 6.0.400
maccatalyst                 15.4.454/6.0.400      SDK 6.0.400
maui                        6.0.540/6.0.400       SDK 6.0.400
tvos                        15.4.454/6.0.400      SDK 6.0.400
android                     32.0.465/6.0.400      SDK 6.0.400
android-33                  32.0.465/6.0.400      SDK 6.0.400

Build Logs

Example Project (If Possible)

@rolfbjarne
Copy link
Member

Try doing this:

using ObjCRuntime;

var image = Runtime.GetINativeObject<CGImage> (imageRef, false);

does that work for you?

@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Oct 11, 2022
@ghost
Copy link

ghost commented Oct 11, 2022

Hi @Cheesebaron. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@Cheesebaron
Copy link
Author

@rolfbjarne yep, that seems to work.

@ghost ghost added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Oct 12, 2022
@chamons
Copy link
Contributor

chamons commented Oct 12, 2022

That is the supported path forward, as the IntPtr constructors are no longer public.

Thanks for the feedback.

@chamons chamons closed this as completed Oct 12, 2022
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Oct 13, 2022
…CGImagesAsynchronously.

Add an overload to AVAssetImageGenerator.GenerateCGImagesAsynchronously that
takes a callback we call with a managed CGImage instance instead of a CGImage handle.

This makes the API a bit easier to use.

Ref: dotnet#16314
@rolfbjarne
Copy link
Member

I'm adding an overload that takes a callback that will be given the CGImage instance (instead of the handle): #16325.

rolfbjarne added a commit that referenced this issue Oct 14, 2022
…CGImagesAsynchronously. (#16325)

Add an overload to AVAssetImageGenerator.GenerateCGImagesAsynchronously that
takes a callback we call with a managed CGImage instance instead of a CGImage handle.

This makes the API a bit easier to use.

Ref: #16314
@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need-attention An issue requires our attention/response
Projects
None yet
Development

No branches or pull requests

3 participants