- Home /
Question by
Yakov_domnicky · May 13, 2020 at 09:20 PM ·
scaleui image
How to stretch photo from camera to look like video streaming from camera to screen
Hello everyone! I'm making an app for IOS, want to make photo's with app I'm trying to scale photo from camera so it looks like the video is streaming on the screen before user took photo
The problem is, that the texture I get from camera is 1920*1440 when screen is 1792*828 I don't know, how to scale correctly Thank you for any help!
Comment
Answer by Yakov_domnicky · May 13, 2020 at 11:29 PM
Answer is:
public unsafe void GetScreenShot()
{
if (!cameraManager.TryGetLatestImage(out image))
{
return;
}
var format = TextureFormat.RGBA32;
Texture2D texture = new Texture2D(image.width, image.height, format, false);
var conversionParams = new XRCameraImageConversionParams {
inputRect = new RectInt(0, 0, image.width, image.height),
outputDimensions = new Vector2Int(image.width, image.height),
outputFormat = TextureFormat.RGBA32,
transformation = CameraImageTransformation.MirrorY
};
var rawTextureData = texture.GetRawTextureData<byte>();
try
{
IntPtr ptr = new IntPtr(rawTextureData.GetUnsafePtr());
image.Convert(conversionParams, ptr, rawTextureData.Length);
}
finally
{
// We must dispose of the XRCameraImage after we're finished
// with it to avoid leaking native resources.
image.Dispose();
}
// Apply the updated texture data to our texture
texture.Apply();
// Set the RawImage's texture so we can visualize it
Fit.aspectRatio = (float) image.width / image.height;
Fit.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth;
background.texture = texture;
background.rectTransform.localEulerAngles = new Vector3(0, 0, 90);
background.enabled = true;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612234209im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity UI constant physical size one image 0 Answers
UI Image Scaler 0 Answers
How do I size a UI Image to fit the sprite exactly? 2 Answers
How do you handle a scaledown animation on a UI button? 0 Answers
UI and Collision Detection zone 0 Answers