ImageFromXamarinUI icon indicating copy to clipboard operation
ImageFromXamarinUI copied to clipboard

CaptureImageAsync used on an OpenGLView produces blank results

Open pfafft33 opened this issue 4 years ago • 15 comments

I've got a Xamarin.Forms / Android app that displays graphics in an OpenGLView. I'm trying to use the NuGet "ImageFromXamarinUI" to capture an instantaneous screenshot of the graphics at a point in time, and save it to a file.

My "capture" code currently looks like:

                Stream imageStream = await myPage.myOpenGLView.CaptureImageAsync();

                string myCaptureFilename = $"MLM - {ParamsEqSetName} - {System.DateTime.Now.ToString("yyyy_MM_d_HH_mm")}";

                using (Stream stream = File.Open($"/storage/emulated/0/Pictures/{myCaptureFilename}", FileMode.Create))
                {
                    imageStream.CopyTo(stream);
                    stream.Close();
                    stream.Dispose();
                }

The file is being created successfully. But, when I try to open it as an image with the Photos app, I get a blank, black screen.

I expect to see the graphics that were being displayed at the moment that I executed the capture code. Instead, I get a blank, black screen.

Any help would be appreciated.

pfafft33 avatar Feb 25 '21 12:02 pfafft33

@pfafft33 Hi Could you please send a sample project?

dimonovdd avatar Feb 25 '21 13:02 dimonovdd

Does your code work correctly with other views? (ContentView, StackLayout, Button and etc.)

dimonovdd avatar Feb 25 '21 13:02 dimonovdd

It works correctly with a Button view. So, the issue seems to be specific to OpenGLView.

pfafft33 avatar Feb 25 '21 13:02 pfafft33

I added more samples to this project. Yes, there is this problem with OpenGLView on iOS and android. I will try to fix this issue.

dimonovdd avatar Feb 25 '21 21:02 dimonovdd

Thanks for the update! Let me know if there is anything that I can do to help with fixing this issue. This functionality will add nicely to my app, when it is working.

pfafft33 avatar Feb 25 '21 22:02 pfafft33

@pfafft33 Hi. I'm currently reading about capturing an image from the OpenGLView. It looks scary, I'll have to add extra dependencies to the plugin. Maybe right way would be to create a new plugin for this issue. Something like that the names ImageFromXamarinUI.OpenGLView

https://stackoverflow.com/questions/5514149/capture-screen-of-glsurfaceview-to-bitmap

dimonovdd avatar Feb 28 '21 21:02 dimonovdd

Hi:

I could see creating a new plugin might create less risk to your current code. But, you might also end up duplicating a fair amount of work.

Let me know what you decide. Give me a shout-out any time, to bounce ideas around.

Sincerely,

Terence A. Pfaff

TAP Brands LLC

From: Dimov Dima [email protected] Sent: Sunday, February 28, 2021 3:35 PM To: dimonovdd/ImageFromXamarinUI [email protected] Cc: Terence A. Pfaff [email protected]; Mention [email protected] Subject: Re: [dimonovdd/ImageFromXamarinUI] CaptureImageAsync used on an OpenGLView produces blank results (#3)

@pfafft33 https://github.com/pfafft33 Hi. I'm currently reading about capturing an image from the OpenGLView. It looks scary, I'll have to add extra dependencies to the plugin. Maybe right way would be to create a new plugin for this issue. Something like that the names ImageFromXamarinUI.OpenGLView

https://stackoverflow.com/questions/5514149/capture-screen-of-glsurfaceview-to-bitmap

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dimonovdd/ImageFromXamarinUI/issues/3#issuecomment-787527086 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ALKPGROFFX4KCV3QP7ER3JLTBKZIFANCNFSM4YGOSPCA .

pfafft33 avatar Feb 28 '21 22:02 pfafft33

How do you add a reference to OpenGLView in your android project?

<ItemGroup>
  <Reference Include="Mono.Android" />
  <Reference Include="OpenTK-1.0" />
</ItemGroup>

dimonovdd avatar Mar 01 '21 20:03 dimonovdd

OpenGLView is a Xamarin Forms construct.

You should start off by creating your initial project using the Xamarin.Forms template in the Add New Project dialog choose: “Mobile App (Xamarin.Forms)”.

From: Dimov Dima [email protected] Sent: Monday, March 01, 2021 2:06 PM To: dimonovdd/ImageFromXamarinUI [email protected] Cc: Terence A. Pfaff [email protected]; Mention [email protected] Subject: Re: [dimonovdd/ImageFromXamarinUI] CaptureImageAsync used on an OpenGLView produces blank results (#3)

How do you add a reference to OpenGLView in your android project?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dimonovdd/ImageFromXamarinUI/issues/3#issuecomment-788234063 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ALKPGROZMWAQPLCKXEDVFXDTBPXTDANCNFSM4YGOSPCA .

pfafft33 avatar Mar 01 '21 20:03 pfafft33

This is understandable, but you still need platform-dependent code to draw graphics. Is my sample different from yours? Can you send me a small sample project where you use the OpenGL? OpenGLViewSharedCode

dimonovdd avatar Mar 01 '21 20:03 dimonovdd

I have Mono.Android referenced in my Android project, and OpenTK-1.0 referenced in my Xamarin shared-code project.

From: Dimov Dima [email protected] Sent: Monday, March 01, 2021 2:16 PM To: dimonovdd/ImageFromXamarinUI [email protected] Cc: Terence A. Pfaff [email protected]; Mention [email protected] Subject: Re: [dimonovdd/ImageFromXamarinUI] CaptureImageAsync used on an OpenGLView produces blank results (#3)

This is understandable, but you still need platform-dependent code to draw graphics. Is my sample different from yours? Can you send me a small sample project where you use the OpenGL? OpenGLViewSharedCode https://github.com/dimonovdd/ImageFromXamarinUI/blob/main/Sample/Sample.Android/OpenGLViewSharedCode.cs

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dimonovdd/ImageFromXamarinUI/issues/3#issuecomment-788240932 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ALKPGROBW4P6HJ6IJSQIHM3TBPYZNANCNFSM4YGOSPCA .

pfafft33 avatar Mar 01 '21 21:03 pfafft33

this is very easy to do on iOS

But on android, this is very strange. We need to call image capture in GLSurfaceView.onDrawFrame() method. To do this, we will have to write a custom renderer class for OpenGLView. This is beyond the scope of this plugin.

Perhaps you have some ideas on this?

dimonovdd avatar Mar 02 '21 18:03 dimonovdd

I’ve never written a custom renderer. As a matter of fact, the App that I’ve just put up on the Google Play Store is the first Android App that I’ve ever written.

I have also contacted the people at Microsoft, because they have a NuGet called Xamarin.Essentials that is supposed to do screen capture also, but has the same issue with the OpenGLView.

Maybe we’ll both get lucky and they will decide to fix this issue in Xamarin.Essentials.

By the way, if you would like to see my App, do a search on the Google Play Store for “Meditate-Lemniscate”. There’s a 30-day free trial, so you can take a look at it. I would really appreciate any feedback.

Sincerely,

Terence A. Pfaff

TAP Brands LLC

From: Dimov Dima [email protected] Sent: Tuesday, March 02, 2021 12:21 PM To: dimonovdd/ImageFromXamarinUI [email protected] Cc: Terence A. Pfaff [email protected]; Mention [email protected] Subject: Re: [dimonovdd/ImageFromXamarinUI] CaptureImageAsync used on an OpenGLView produces blank results (#3)

this is very easy to do on iOS https://github.com/dimonovdd/ImageFromXamarinUI/blob/576e4fb756d5ec1565de244939c53c68e90e266b/ImageFromXamarinUI.OpenGLView/OpenGLViewExtension.ios.cs#L50

But on android, this is very strange. We need to call image capture in GLSurfaceView.onDrawFrame() method. To do this, we will have to write a custom renderer class for OpenGLView. This is beyond the scope of this plugin.

Perhaps you have some ideas on this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dimonovdd/ImageFromXamarinUI/issues/3#issuecomment-789112290 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ALKPGRNKXZTKGAJSES446JLTBUUA3ANCNFSM4YGOSPCA .

pfafft33 avatar Mar 02 '21 19:03 pfafft33

@pfafft33 I think this problem does not apply to Essentials. This behavior has ios and android. Where did you create the new issue? I don't see your issue here https://github.com/xamarin/Essentials/issues

dimonovdd avatar Mar 02 '21 19:03 dimonovdd

https://github.com/xamarin/Essentials/issues/1702

From: Dimov Dima [email protected] Sent: Tuesday, March 02, 2021 1:23 PM To: dimonovdd/ImageFromXamarinUI [email protected] Cc: Terence A. Pfaff [email protected]; Mention [email protected] Subject: Re: [dimonovdd/ImageFromXamarinUI] CaptureImageAsync used on an OpenGLView produces blank results (#3)

@pfafft33 https://github.com/pfafft33 I think this problem does not apply to Essentials. This behavior has ios and android. Where did you create the new problem? I don't see your problem here https://github.com/xamarin/Essentials/issues

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dimonovdd/ImageFromXamarinUI/issues/3#issuecomment-789152489 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ALKPGRKVBYQ27W2XWOR33FTTBU3IFANCNFSM4YGOSPCA .

pfafft33 avatar Mar 02 '21 19:03 pfafft33