StansAssets / com.stansassets.ios-native

iOS Native Plugin Wiki
https://api.stansassets.com/
10 stars 1 forks source link

Newbie question on Photo Capture #55

Closed JoergPf closed 3 years ago

JoergPf commented 3 years ago

Hi, sorry for this basic question, I just started with Unity and would like to use the iOS Camera. I successfully installed iOS-Native Pro. I have just a Button that should start the camera.

I do

using SA.iOS.AVFoundation;
using SA.iOS.UIKit;
using UnityEngine;

public class myEng : MonoBehaviour
{
    public void takePhoto()
    {
        ISN_UIImagePickerController picker = new ISN_UIImagePickerController();
        picker.SourceType = ISN_UIImagePickerControllerSourceType.Camera;
        picker.CameraDevice = ISN_UIImagePickerControllerCameraDevice.Rear;
        picker.MediaTypes = new List<string>() { ISN_UIMediaType.IMAGE };
        picker.MaxImageSize = 512;
        picker.ImageCompressionFormat = ISN_UIImageCompressionFormat.JPEG;
        picker.ImageCompressionRate = 0.8f;

        picker
            .Present((result) =>
            {
                if (result.IsSucceeded)
                {
                    Debug.Log("IMAGE local path: " + result.ImageURL);

                    //Example how to assing thumbnail to Image m_image
                    m_image.sprite = result.Image.ToSprite();

                    //Example how to assing thumbnail to GameObject m_go;
                    m_go.GetComponent<Renderer>().material.mainTexture =
                        result.Image;
                }
                else
                {
                    Debug
                        .Log("Media picker failed with reason: " +
                        result.Error.Message);
                }
            });
    }
}

But it seems I'm missing a Library: Assets/Scripts/myEng.cs(94,21): error CS0103: The name 'm_image' does not exist in the current context

Best Joerg

stan-osipov commented 3 years ago

Hey. So this example is trying to assign a picked image to the UIGUIImage component https://docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.Image.html

You need to declare and assign m_image in your script. so add

[SerializeField] Image m_image; to your script, create an Image in a scene, put your script to any game object, drag and drop a scene image to your script. Hope it helps!