Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Path #11

Closed
mole84 opened this issue Nov 28, 2017 · 7 comments
Closed

File Path #11

mole84 opened this issue Nov 28, 2017 · 7 comments

Comments

@mole84
Copy link

mole84 commented Nov 28, 2017

Hi,
how can I get the file path of the selected picture ? Its always the same path in the debug log

@thedoritos
Copy link
Owner

Hi, @mole84

I expect to get path like the demo code on the README.

https://github.com/thedoritos/unimgpicker/blob/master/README.md

Could you provide more information? Such as...

  • The code you wrote to get the path.
  • The error log you got.

Thank you.

@mole84
Copy link
Author

mole84 commented Nov 29, 2017

There is no error any more, but if I use your example (without changing something), and I ulpoad something from my C:/ it returns me the following path in Debug.Log:
C:/Users/mole/AppData/LocalLow/kakeragames/unimgpicker/unimgpicker

But i uploaded the file from "C:/" , so the path is wrong.
It´s always the same path, no matter where I upload the file from

How do i get the path with filename?

by the way, the image is shown correctly on the cube.

@thedoritos
Copy link
Owner

Thanks for the info.
Now I see what was your question.

Currently, Unimgpicker doesn't have a feature to get the original image path.

This is a security problem on iOS/Android. The path is abstracted on these platform and you can't read the file directly from the path. As a workaround, Unimgpicker copies the image to the app data directory where your app can read/write.

I assume you want the original filename. If you really need it, I would try! But it seems that we have to switch the image picking framework (for iOS), and it'll take a little more than a few days.

Thank you.

@mole84
Copy link
Author

mole84 commented Dec 2, 2017

Hi thedoritos,

thank you for reply.
I like to upload the selected file and maybe it is possible to convert and save the meshrenderer into jpg or png? If this is possible theres no need for getting the original filename.

Do you have an idea?

@thedoritos
Copy link
Owner

Hi, @mole84

There is a workaround.

  1. Pick an image.
  2. Copy the image file at the path to anywhere you want.
  3. Do anything you like with the new file.

Note that the image Unimgpicker returns is not the original one. It is a copy as I mentioned above. And it may be downscaled according to the size argument you'll pass.

If you pass a large number, you may get a high quality copy but it probably causes an OutOfMemory error.

Thank you.

@mole84
Copy link
Author

mole84 commented Apr 3, 2018

Hi thedoritos,

how to copy the image?

  1. Copy the image file at the path to anywhere you want.

@mole84
Copy link
Author

mole84 commented Apr 3, 2018

I did it that way and it is working:

`using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;

namespace Kakera
{
public class PickerController : MonoBehaviour
{
[SerializeField]
private Unimgpicker imagePicker;

   // [SerializeField]
   // private MeshRenderer imageRenderer;

    void Awake()
    {
        imagePicker.Completed += (string path) =>
        {
            StartCoroutine(LoadImage(path));
        };
    }

    public void OnPressShowPicker()
    {
        imagePicker.Show("Select Image", "unimgpicker", 1024);
    }

    private IEnumerator LoadImage(string path)
    {
        var url = "file://" + path;
        var www = new WWW(url);
        yield return www;

        var texture = www.texture;
        if (texture == null)
        {
            Debug.LogError("Failed to load texture url:" + url);
        }

        //output.material.mainTexture = texture;

			var pngData = texture.EncodeToPNG();
		if (pngData != null ){
			Debug.Log (Application.persistentDataPath);
			File.WriteAllBytes(Application.persistentDataPath + "/" +"testpic" + ".png", pngData);
				}
			else
				Debug.Log("Could not convert " + texture.name + " to png. Skipping saving texture");
		
			
    }
}

}`

@mole84 mole84 closed this as completed Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants