Skip to content

Feat: screenshots - #670

Merged
vaind merged 18 commits into
mainfrom
feat/screenshots
Apr 21, 2022
Merged

vaind merged 18 commits into
mainfrom
feat/screenshots

Conversation

@vaind

@vaind vaind commented Mar 30, 2022 •

Copy link
Copy Markdown
Contributor

Closes #284

TODO:

@bruno-garcia

Copy link
Copy Markdown
Member

We can also replace this sample then:

public void CaptureMessageWithScreenshot() => StartCoroutine(CaptureScreenshot());

@lucas-zimerman

Copy link
Copy Markdown
Collaborator

Out of curiosity, does this feature works with UWP? I recall on Xamarin that when I tried to take a screenshot it usually freezes the app on UWP so I just disabled it on that platform 😅

@vaind

vaind commented Apr 4, 2022

Copy link
Copy Markdown
Contributor Author

We can also replace this sample then:

public void CaptureMessageWithScreenshot() => StartCoroutine(CaptureScreenshot());

Replace by what though? I'd actually remove that.

@vaind

vaind commented Apr 4, 2022

Copy link
Copy Markdown
Contributor Author

Out of curiosity, does this feature works with UWP? I recall on Xamarin that when I tried to take a screenshot it usually freezes the app on UWP so I just disabled it on that platform 😅

While UWP isn't officially supported (a.k.a tested), the screenshot attachment seems to work fine:

{"type":"attachment","length":100262,"filename":"screenshot.jpg","attachment_type":"event.attachment","content_type":"image/jpeg"}

Though I can't verify if the actual screenshot looks reasonable because there are HTTP Request errors despite enabling some internet-related permissions in the player settings:

Sentry: (Error) Failed to send cached envelope: C:/Users/dlugo/AppData/Local/Packages/Template2D_pzq3xp76mxafg/LocalState\Sentry\618762E37120B6E01219C43B9076FFEC1ACE8406\__processing\1649084082_-4848__1273990338.envelope, type: HttpRequestException, retrying after a delay. System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: NameResolutionFailure
  at System.Net.HttpWebRequest.EndGetRequestStream (System.IAsyncResult asyncResult) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Func`2[T,TResult].Invoke (T arg) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.TaskFactory`1+<>c__DisplayClass35_1[TResult].<FromAsyncImpl>b__1 (System.IAsyncResult iar) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.Windows.WebCam.PhotoCapture+OnCaptureResourceCreatedCallback.Invoke (UnityEngine.Windows.WebCam.PhotoCapture captureObject) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.SimpleAsyncCallback.Invoke (System.Net.SimpleAsyncResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.HttpWebRequest.SetWriteStreamError (System.Net.WebExceptionStatus status, System.Exception exc) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.WebConnection.InitConnection (System.Net.HttpWebRequest request) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.WebConnection.<SendRequest>b__41_0 (System.Object o) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 

Comment on lines +42 to +43
[field: SerializeField] public int ScreenshotMaxWidth { get; set; }
[field: SerializeField] public int ScreenshotMaxHeight { get; set; }

@bitsandfoxes bitsandfoxes Apr 8, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about dealing with absolute pixel sizes here. It does not take into account devices with different aspect ratios or switching from portrait to landscape.
Maybe we should start with a ratio instead e.g. "half the original resolution".

@lucas-zimerman lucas-zimerman Apr 12, 2022 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use a single parameter for Width/Height that gets applied to the highest value and if the image is bigger than the given maximum value, resize it while keeping the aspect ratio.

Sample code that I used to use for getting a new size for the image

        private static SKImageInfo GetResizedMeasure(int width, int height, int newMax)
        {
            double ratio;
            if (width > newMax)
            {
                ratio = (double)newMax / width;
                height = (int)(height * ratio);
                width = (int)(width * ratio);
            }
            if (height > newMax)
            {
                ratio = (double)newMax / height;
                width = (int)(width * ratio);
                height = (int)(height * ratio);
            }
            return new SKImageInfo(width, height, SKColorType.Rgb565);
        }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've discussed in the call to align across other SDKs. @bitsandfoxes is going to gather inputs

@vaind
vaind force-pushed the feat/screenshots branch from c5ff9d6 to b1562b4 Compare April 13, 2022 06:33
Comment thread CHANGELOG.md Resolved
@vaind

vaind commented Apr 20, 2022

Copy link
Copy Markdown
Contributor Author

I've disabled for WebGL where the screenshots consistently don't work (they're black), and updated the tooltip with more information. If you think that's OK for now, please merge @bitsandfoxes or @bruno-garcia

Comment thread src/Sentry.Unity/SentryUnity.cs Resolved
@vaind
vaind force-pushed the feat/screenshots branch from 8170b8f to 77e95c5 Compare April 21, 2022 13:42
@vaind
vaind merged commit d49cf66 into main Apr 21, 2022
@vaind
vaind deleted the feat/screenshots branch April 21, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add AttachScreenshot option

5 participants