void testLocalPhoto2()
    {
        object    textureObj = Resources.Load("test2", typeof(Texture2D));
        Texture2D texture    = (Texture2D)textureObj;

        //texture.anisoLevel = 1;
        //texture.filterMode = FilterMode.Bilinear;
        //texture.wrapMode = TextureWrapMode.Clamp;

        //scale to small size
        int aScaleSize = MediaBase.getAScaleSize(texture.width);

        TextureScale.Bilinear(texture, texture.width / aScaleSize, texture.height / aScaleSize);

        JpegInfo jpi   = ExifReader.ReadJpeg(texture.EncodeToJPG(), "Foo");
        int      angle = 0;

        switch (jpi.Orientation)
        {
        case ExifOrientation.TopLeft:
            break;

        case ExifOrientation.TopRight:
            angle = -90;
            break;

        case ExifOrientation.BottomLeft:
            angle = 90;
            break;

        case ExifOrientation.BottomRight:
            angle = 180;
            break;
        }
        texture = TextureRotate.RotateImage(texture, angle);

        Sprite picture = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 1);

        PictureLoaded(true, "", picture);
    }
示例#2
0
    IEnumerator LoadPictureCoroutine(string path)
    {
        WWW www = new WWW(path);

        if (www.size == 0)
        {
            showlog("size 0");
            yield return(new WaitForSeconds(1.0f));

            LoadPicture(path);
        }
        else if (!string.IsNullOrEmpty(www.error))
        {
            showlog("error");
            PictureLoaded(false, null, null);
        }
        else
        {
            ExifLib.JpegInfo jpi = ExifLib.ExifReader.ReadJpeg(www.bytes, "test2.jpg");
            showlog("EXIF: " + jpi.Orientation);

            Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.RGB24, false);

            texture.anisoLevel = 1;
            texture.filterMode = FilterMode.Bilinear;
            texture.wrapMode   = TextureWrapMode.Clamp;

            www.LoadImageIntoTexture(texture);

            TextureScale.Bilinear(texture, texture.width / 10, texture.height / 10);
            texture = TextureRotate.RotateImage(texture, -90);

            Sprite picture = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 1);
            PictureLoaded(true, path, picture);
        }
    }
示例#3
0
    public void OnTakePictureButtonPressed()
    {
//#if UNITY_EDITOR
//        Picture = TestPicture;
//#else
        WebCamTexture wct = CameraController.GetActiveTexture();

        Picture = new Texture2D(wct.width, wct.height);
        Picture.SetPixels(wct.GetPixels());

        if (wct.videoRotationAngle == 90)
        {
            TextureRotate.RotateTexture(Picture, TextureRotate.Rotate.Right);
        }
        //for rect image could be used crop
        // like Picture.ReadPixels(new Rect(0,0,512,512),0,0);
        Picture.Apply();
//#endif
        if (OnPictureTakenCallback != null)
        {
            OnPictureTakenCallback(Picture);
        }
        ClosePopup();
    }
    IEnumerator LoadPictureCoroutine(string path)
    {
        WWW www = new WWW(path);

        if (www.size == 0)
        {
            showlog("size 0");
            yield return(new WaitForSeconds(1.0f));

            LoadPicture(path);
        }
        else if (!string.IsNullOrEmpty(www.error))
        {
            showlog("error");
            PictureLoaded(false, null, null);
        }
        else
        {
            //ExifLib.JpegInfo jpi = ExifLib.ExifReader.ReadJpeg(www.bytes, "test2.jpg");
            //showlog("EXIF: " + jpi.Orientation);

            //Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.RGB24, false);

            //texture.anisoLevel = 1;
            //texture.filterMode = FilterMode.Bilinear;
            //texture.wrapMode = TextureWrapMode.Clamp;

            //www.LoadImageIntoTexture(texture);

            //TextureScale.Bilinear(texture, texture.width / 5, texture.height / 5);
            //texture = TextureRotate.RotateImage(texture, -90);


            Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.RGB24, false);

            texture.anisoLevel = 1;
            texture.filterMode = FilterMode.Bilinear;
            texture.wrapMode   = TextureWrapMode.Clamp;

            www.LoadImageIntoTexture(texture);

            //scale to small size
            int aScaleSize = MediaBase.getAScaleSize(texture.width);
            TextureScale.Bilinear(texture, texture.width / aScaleSize, texture.height / aScaleSize);

            JpegInfo jpi   = ExifReader.ReadJpeg(www.bytes, "Foo");
            int      angle = 0;
            switch (jpi.Orientation)
            {
            case ExifOrientation.TopLeft:
                break;

            case ExifOrientation.TopRight:
                angle = -90;
                break;

            case ExifOrientation.BottomLeft:
                angle = 90;
                break;

            case ExifOrientation.BottomRight:
                angle = 180;
                break;
            }
            texture = TextureRotate.RotateImage(texture, angle);

            Sprite picture = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 1);
            PictureLoaded(true, path, picture);
        }
    }
示例#5
0
    private IEnumerator LoadPictureCoroutine(string path)
    {
        _count--;

                #if !UNITY_EDITOR && !UNITY_WEBGL
        path = "file://" + path;
                #endif

        WWW www = new WWW(path);
        yield return(www);

        if (www.size == 0)
        {
            yield return(new WaitForSeconds(1.0f));

            LoadPicture(path);
        }
        else if (!string.IsNullOrEmpty(www.error))
        {
            PictureLoaded(false, null, null);
        }
        else
        {
            Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.RGB24, false);

            texture.anisoLevel = 1;
            texture.filterMode = FilterMode.Bilinear;
            texture.wrapMode   = TextureWrapMode.Clamp;

            www.LoadImageIntoTexture(texture);

            //scale to small size
            int aScaleSize = getAScaleSize(texture.width);
            TextureScale.Bilinear(texture, texture.width / aScaleSize, texture.height / aScaleSize);

            JpegInfo jpi   = ExifReader.ReadJpeg(www.bytes, "Foo");
            int      angle = 0;
            switch (jpi.Orientation)
            {
            case ExifOrientation.TopLeft:
                break;

            case ExifOrientation.TopRight:
                angle = -90;
                break;

            case ExifOrientation.BottomLeft:
                angle = 90;
                break;

            case ExifOrientation.BottomRight:
                angle = 180;
                break;
            }
            texture = TextureRotate.RotateImage(texture, angle);

            Sprite picture = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 1);

            PictureLoaded(true, path, picture);
        }
    }