赞
踩
使用NativeGallery插件
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class NewBehaviourScript : MonoBehaviour
- {
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
-
- }
- public RawImage head;
- public void TakePhoto(int maxSize = -1)
- {
- //调用插件自带接口,拉取相册,内部有区分平台
- NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
- {
- Debug.Log("Image path: " + path);
- if (path != null)
- {
- // 此Action为选取图片后的回调,返回一个Texture2D
- Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
- if (texture == null)
- {
- Debug.Log("Couldn't load texture from " + path);
- return;
- }
- Debug.Log(texture.name);
- head.texture = texture;//将选择的图片对我们的RawImage进行赋值
- }
- }, "选择图片", "image/png", maxSize);
- }
-
-
- }
安卓设备需要设置权限到外部储存卡 PlayerSetting-Player-OtherSetting-WritePermission-External
上传服务器 把图片转成字节上传就可以
项目下载https://download.csdn.net/download/qq_36715529/86882031
参照CSDN博主「YOLO_TO_GAME」的原创文章,链接https://blog.csdn.net/weixin_39706943/article/details/81196089
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。