Unity3d - 2 issues with Facebook Sharing in Window Phone - c#

Everybody,I must say that I have post this question 3 times in Unity Community (include answer hub and its forum) but no one can solve it.
I use TakeScreenShot() function (it's in the InteractiveConsole example in FB SDK for Unity) to take a screenshot and post it to FB. But there are 2 problems appeared:
First: the screenshot that's captured is a gray blank like this: http://i7.minus.com/iXiHlCcSWaVfC.jpg
Second: No one can see my post except me although I set the photo to public.
How can I fix these problems?
Here is the code of TakeScreenShot() function:
private IEnumerator TakeScreenshot() {
yield return new WaitForEndOfFrame();
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] screenshot = tex.EncodeToPNG();
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
wwwForm.AddField("message", "herp derp. I did a thing! Did I do this right?");
FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
Debug.Log("done");
}

I hope you solved your issues but I will answer anyways to your questions:
•First: the screenshot that's captured is a gray blank.
I think this works for Windows Phone only since very recently on Unity 4.5, update and try again.
Unity 4.5 Windows Phone Fixes
Grey Textures happen if you forget to call the Apply method. You will end up with a grey texture if forget to call. I see you are calling tex.Apply() but my guess is that you added it later and you may be seeing an old grey texture. Your code should work as it is. If you still get the grey Texture after updating to version 4.5 or later, try to wait a little time between the Apply and calling the EncodeToPNG(), maybe yield between those calls. Bear in mind that both are expensive operations.
•Second: No one can see my post except me although I set the photo to public.
That is because you have not go live (public) with you facebook app, during development only you will see you and your development team will see the messages. By the way fecebook will not approve hardcoded messages so even though this may work, and I know you based your code on facebook own smaples, you will need to allow the user to edit the message before posting.

Related

SkiaSharp drawing with OpenGL/Vulkan backend from console application

I want to draw something with GPU acceleration (using OpenGL or Vulkan) using SkiaSharp and save the image later. There is no need to display the image anywhere in the application, because it's a console application targeting Windows and Linux.
I already tried the following code, with various variations, but nothing worked (raises an exception at var surface = SKSurface.Create(context, false, info); because glInterface and context are null.
Can somebody give me a hint?
var glInterface = GRGlInterface.Create();
var context = GRContext.CreateGl(glInterface);
var info = new SKImageInfo(256, 256);
var surface = SKSurface.Create(context, false, info);
var canvas = surface.Canvas;
In the end it would be nice to have the ability to call SKBitmap.SetPixels(IntPrt) or something similar to set the resulting bitmap buffer to a specific place.
The solution is you need to manually create an OpenGL context first.
Have a look at https://github.com/mono/SkiaSharp/blob/master/tests/Tests/GRContextTest.cs for implementation details.
For copying the rendered pixel buffer you can use SKSurface.ReadPixels.

I need to download a lot of images in Unity but my app freezes on generating Sprite

Here it is my code:
https://pastebin.com/n4dQf7WW
Basically my problem is the fact that I download something like 10/15 images in one time to fill my homepage. But generating all these images will freeze the app on both iOS and Android.
More facts:
- On iOS the download won't start immediately, on Android does.
- I used the UnityWebRequest functions, but on iOS it won't work concurrently.
- On Android it works as it should be, but when it comes to create the Sprite/Texture it freezes until it's finished.
So what I'm asking is if there is a way to handle better this situation (even with third-party library both paid and free).
I think the problem is here on the WebClient_DownloadDataCompleted function:
var texture = new Texture2D(2, 2);
texture.LoadImage(imageBytes);
Rect rec = new Rect(0, 0, texture.width, texture.height);
var spriteToUse = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);

Google VR SDK (Unity) - GvrVideoPlayerTexture swap URL

I'm working with the Google VR SDK for Unity trying to build a simple 360 Video viewer using the components that come with the SDK. I'm trying to extend their PanoVideoSample to dynamically change the source video when the user navigates from a menu.
I'm having trouble changing the URL for the GvrVideoPlayerTexture via code. In their demo scene (VideoDemo) they have a PanoVideoSample that contains a Video Sphere, which you can edit the GVRVideoPlayerTexture script in the inspector panel to point at the proper video URL.
I'd like to dynamically set the video URL in C# rather than hard-code a bunch of individual video spheres then hide/show them. I've almost got this working with the following code.
public void SwapVideo(int index){
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture> ().videoURL = urls [index];// my new url
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture>().ReInitializeVideo ();
videoSphere.SetActive (true);
}
public void ReturnToMainMenu(){
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture>().CleanupVideo();
videoSphere.SetActive (false);
this.gameObject.SetActive (true);
}
The code above seems to work, but the problem is the texture on the videoSphere turns white after the url is set and the texture is re-initialized. I can see that the new video loads and I can hear the audio for the new video, but the scene just shows a white texture.
See the output here
I'm wondering if I'm missing a key step on the GvrVideoPlayerTexture or perhaps additional calls to update the StereoPanoSphereMaterial that is used to render the scene. This SDK is pretty new and there doesn't seem to be many people writing about it, so any help is appreciated.
I eventually found the answer to my question in the documentation on the Google VR docs (Streaming Video Support).
I'm still not totally clear what I was doing wrong in my first attempt, but this is the code that worked for me.
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture> ().videoURL = urls [index];
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture> ().videoType = GvrVideoPlayerTexture.VideoType.Other;
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture> ().videoProviderId = string.Empty;
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture> ().videoContentID = string.Empty;
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture> ().CleanupVideo ();
videoSphere.GetComponentInChildren<GvrVideoPlayerTexture> ().ReInitializeVideo ();

Setting options to images in Magick .NET collection

I'm trying to reduce the file sizes of the GIF animations I'm exporting, I've read up on how to do it. Another thread suggested to reduce the quality, add compression and slightly blur the picture which is what I'm trying to do like so:
using (MagickImageCollection col = new MagickImageCollection(#"C:/PathToGif"))
{
for (int i = 0; i < col.Count; i++)
{
col[i].Quality = 85;
col[i].CompressionMethod = CompressionMethod.LZW;
col[i].Strip();
}
col.Write(#"C:/Path/To/Outputh");
}
The code runs however the settings seem to be ignored, while setting AnimationDelay the same way does work. I verify it by checking the quality and file size of the output, which seem to be the same as when I don't use any of the settings. Even setting quality to 20, gives the same results.
I've also attempted to use QuantizeSettings where I passed a value of 255 to the colors property. Which just seemed to lock my application up, while using 50% CPU. (I gave it about 5 minutes before forcefully closing the application)
My application processes a .GIF of about 950 kB and turns it into 5.3 mB which is unacceptable. (Disclaimer: I add about 20+- frames to the .GIF and draw an overlay on it.)
Could someone who has experience with the Magick .NET library tell me if I'm doing something wrong and point me into the right direction of doing this? I was unable to find a different way of applying these settings.
The GIF coder does not use the Quality setting and the CompressionMethod will always be CompressionMethod.LZW. You should do the following if you want to optimize the output file:
using (MagickImageCollection col = new MagickImageCollection(#"C:/PathToGif"))
{
col.Coalesce();
AddOtherImages(col);
col.Optimize();
col.OptimizeTransparency();
col.Write(#"C:/Path/To/Output");
}
Make sure you upgrade to the latest version, the Optimize/OptimizeTransparency methods were bugged in previous versions.

Captured photo with stripes

I'm using MediaCapture class to take a photo with Windows Phone 8.1 Runtime. The code, where I take a picture looks like this:
// create a file
StorageFile photoFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("myFirstPhoto.jpg", CreationCollisionOption.ReplaceExisting);
// take a photo with choosen Encoding
await captureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoFile);
The code is working quite fine, as I get a picture, but with strange stripes on left and right side:
I'm trying to find a solution for this problem, but without success. Am I missing something?
EDIT - Photos takes from build-in app are without stripes, so this seems not to be a problem with hardware.
Ok I've figured it out myself - it's a problem with resolution which is set as default when using MediaCapture. If you set maximum resolution just after Initializing MediaCapture then there will be no stripes:
// just after initialization
var maxResolution = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate(
(i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
I tried with the lowest resolution it gets the same stripes.
From MS Advance Camera sample, they use MediaCapture for preview but SilverLight API for capturing!
The MediaCapture has also memory leak issue each time when you call CapturePhotoToXXX API.
I wonder if they already know MediaCapture is badly managed on WindowsPhone 8.1 and this is the reason why they don't provide a Camera MediaCapture sample with RT APIs.

Categories

Resources