Taking screenshot of partial area in Unity? - c#

My game lets you dress up your character. I would like to save off that image (but not the rest of the 800x600 screen) to a file. According to the help, I can use Application.CaptureScreen() to capture the full screen but how does one capture just one part of it?

If you want full control over what area you want to screenshot, I would recommend setting up a new camera with a RenderTexture. This will enable a more flexible way of controlling your composition for your screenshots. Like the Avatar Creator on Xbox360.
Create a new camera and align it to fit the image and composition of choice.
Add a RenderTexture
Use ReadPixels to read from the RenderTexture into a Texture2D and save using EncodeToPNG.
Save to disk or upload to server
http://docs.unity3d.com/Manual/class-RenderTexture.html
http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToPNG.html

Related

SharpMap - display an overlay image synchronized with the map (georeferencing functionality)

Using SharpMap (Windows Forms) how can I display an overlay image over the map tile background so that the image scales and moves accordingly with the map zoom and pan? I want to implement a georeferencing like functionality.
I tried using SharpMap.Layers.GdiImageLayer but I didn't find a way to position it to a custom position (real world coordinate) - it is getting placed by default at origin [0,0] (the background tile coordinates). Is there a way to define a relation (transformation) to place it in a particular position?
I managed to get closer to a solution using VectorLayer with RasterPointSymbolizer but the symbol (image loaded for symbol) would need to be transformed on map scaling/zoom (so that corners remain in the same real world coordinates) - the math calculation behind looks a little complicated for a solution that seems more like a workaround than a natural one. As a note - I don't need precise calculation using projection/real geoid as I am doing this only at building level.
Using GDAL - GeoTIFF might be a choice here by generating a GeoTIFF based on the original image and making the georeferencing metadata dynamic based on UI controls? The original image is in raster format (JPG) with no geographic metadata.
Is there a better solution?
If VectorLayer - RasterPointSymbolizer is the best choice, do you have an example for symbol(image) synchronization with the map view?
As far as i can tell the GdiImageLayer calculates the position based on a world-file (GdiImageLayer.SetEnvelope()). Here is the link to the method. This meta file has to have the same name in the same location but the filetype must be of type *.wld. There you set the position (top left corner) and the skew in x and y axis. So rotation will be perserved. I never tried this but i would suggest correct zooming would work
(The wiki article offers also some good understanding for world files)
There might be another way if no world file is present and the information rests in the header. There is a GDalSample loading a GeoTiff Image onto an existing map. The example can be found in the WinFormSamples and the Different kind of layers supported by [MapBox] Example. The map is showing the overlay only while magnifying and not fully function but maybe a good hint

How to scale objects with screen size in Unity

For canvas item no problem, buttons or any other UI elements can be scaled with screensize. On the other hand, I can not do this for objects. I need a box in my design and in every screensize it should fit all screen.
I need this design.
But when I change screensize design does not remain same.
other image:
For button or canvas elements there is no problem I can do it by "scale with screen size" but when it comes to objects I can not do like this. How can I do?
It seems like a vignette would be useful rather than scaling a gameobject.
Quick explanation:
With Unity's post-processing properly added and a volume created, add the effect/override of vignette and change vignette's mode to mask. And add an image as a mask.
If not experienced with post-processing:
For unity 3d HDRP or URP(may work with unity 2d but probably not):
Add a global volume through the hierarchy by first navigating to the plus sign drop-down then to volume then click on global volume. If unavailable, add an empty object with a volume component. Create a profile then add the override of the vignette. Under vignette change the mode to mask and select an image you want the mask to be.
That should be all for unity HDRP or URP.
Without HDRP or URP:
Add the postprocessing package if not installed via the package manager.
Create an empty object and add post-processing volume. Checkmark is-global. Create a new post-processing profile. Add effect vignette. Checkmark 'Mode' and switch it to masked.
Checkmark and change 'Mask' to the image you want.
This should allow the image to pop up over the camera.
Extra note: Make Sure The Image Has A Transparent Background On The Vignette Mask Where You Want The Player To See Through
Please search for how to use post-processing package if any issues occur.

How to put a picture exactly on the road?

I created Custom Pin in Xamarin.Forms.Maps and add my icon. How I can put my icon on the road and and move this icon along.My problem is not with getting accurate data, but with displaying the image itself exactly on the road. For example, if the road is horizontal, then the icon (car) should stand horizontally on the road
You could use Map Tracking. It would show the driver route and car position on the map. The car should move according to its current position in the route.
Install the Xamarin.Forms.GoogleMaps.
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
You could download the source file from the GitHub for reference.
https://github.com/WendyZang/MapTrackingSample

What is the correct method for showing a full screen photo within a mobile app using Unity?

I am creating a mobile app using Unity. I would like to place a photo which fills the screen and then place some 3D objects on top of this photo. The photo is created during runtime and is saved to the persistance data folder.
What is the best method to achieve this? The options I see are Raw Image/Image/Sprite. However, I have been unable to achieve the above mentioned goal using either of these component types.
What about making a panel on a canvas, setting the image as background and the canvas to fit screen size?
Then place the objects on front of it, manually or as children of said canvas but higher in the hierarchy.
I don't really understand what you intend to do, just trying to help.
editing my original answer: you need to use RawImage to be able to easily load images that are not marked as Sprite in the editor
You load images from file like this :
Texture2D texture = new Texture2D(1,1); // the following needs a non null starting poin
var path=System.IO.Path.Combine(Application.streamingAssetsPath,"your_file.jpg");
byte[] bytes=System.IO.File.ReadAllBytes(path);
texture.LoadImage(bytes);
rawImage.texture=texture;
As far as keeping it filling the screen the AspectRatioFiter component is likely to do the job
To get 3d objects rendering in front, set your canvas to 'Screen Space - Camera' and point it to your camera. This will behave similar to word space in regards to rendernig order (will get 3d sroted) but canvas size will match camera viewport, so AspectRatioFitter will be able to do its job

Why my Canvas is not on same positions as on my device?

I hope I am not too boring because again I have one dumb question.
I have made my game near till end but now I have one big problem. My images , text etc in my Canvas panel are not display correctly on all devices.
I made the game and it looks perfect on unity. Then I build the same game to my Galaxy S8 Device and i realized that some images are out of the screen in other words I can not see some images in corners or some text .. That means my canvas settings are not correct ..
This is my canvas settings.
When I change UI scale mode to constant pixel or constant physical size It doesn't show properly even in unity or on phone seems like he zoom in automaticlly too much. I made the best settings for UI SCALE MODE - > Scale with screen size, but on some devices it doesn't show up correctly ( it shows with little errors like corner text is not shown because it looks like he is outside of screen)
I hope someone has solution for this.
Here is my general settings of canvas, which i always use and never got any issue in positioning.
Also when you put any object, RectTransform's value(marked in following image) is not set properly then it will go outside of screen.
For more details see : https://docs.unity3d.com/Manual/class-RectTransform.html
Also you can check different screen ratio from unity and even add new to it and test.

Categories

Resources