Skip to content

UIGraphicsImageRenderer in background thread #22597

@yaliashkevich

Description

@yaliashkevich

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

ios workload 18.0.8319/8.0.100

Description

UIGraphicsRenderer API is thread safe to use on background thread despite having "UI" prefix, it is just convenient wrapper around Core Graphics.
https://developer.apple.com/forums/thread/774527?answerId=825346022#825346022

Corresponding dotnet apis are forced to be main thread only

[Register("UIGraphicsRenderer", true)]
[SupportedOSPlatform("maccatalyst")]
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("tvos")]
public class UIGraphicsRenderer : NSObject
{
	[BindingImpl((BindingImplOptions)3)]
	private static readonly NativeHandle class_ptr = ObjCRuntime.Class.GetHandle("UIGraphicsRenderer");

	public override NativeHandle ClassHandle => class_ptr;

	[BindingImpl((BindingImplOptions)3)]
	public virtual bool AllowsImageOutput
	{
		[Export("allowsImageOutput")]
		get
		{
			UIApplication.EnsureUIThread();
			byte ret = ((!base.IsDirectBinding) ? Messaging.bool_objc_msgSendSuper(base.SuperHandle, Selector.GetHandle("allowsImageOutput")) : Messaging.bool_objc_msgSend(base.Handle, Selector.GetHandle("allowsImageOutput")));
			return ret != 0;
		}
	}

So I can not use it to generate images in background.
For instance you can not implement custom SDImageTransformer due to the fact that transformations are being executed on background thread
https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#transformer-50

Steps to Reproduce

no specific steps

Did you find any workaround?

There is a workaround with UIGraphics.BeginImageContext but it is deprecated already in favour to UIGraphicsImageRenderer
https://developer.apple.com/documentation/uikit/uigraphicsbeginimagecontextwithoptions(_:_:_:)?language=objc

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions