zoukankan      html  css  js  c++  java
  • unity调用 安卓相册

    
    

    把 avtivity.java 里面的内容拷贝到你的mainActivity里面

    
    

    在unity里面调用TakePhoto

    
    

    SdkUtil.SendMessageOpenPhoto(FILE_NAME);这个我注释掉的地方是回调到unity里面的
    访问路径用 Application.persistentDataPath/FILE_NAME 就能拿到图片





    public
    void TakePhoto(String str,String path) { if(str.equals("TakePhoto")) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "temp.jpg"))); startActivityForResult(intent, PHOTOHRAPH); }else { Intent intent = new Intent(Intent.ACTION_PICK, null); intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_UNSPECIFIED); startActivityForResult(intent, PHOTOZOOM); } } public void startPhotoZoom(Uri uri) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, IMAGE_UNSPECIFIED); intent.putExtra("crop", "true"); // aspectX aspectY ? ?? intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // outputX outputY ?ü ?? intent.putExtra("outputX", 300); intent.putExtra("outputY", 300); intent.putExtra("return-data", true); startActivityForResult(intent, PHOTORESOULT); } public void SaveBitmap(Bitmap bitmap) throws IOException { FileOutputStream fOut = null; //注解1 String path = "/mnt/sdcard/Android/data/com.sainthyler.muffin/files"; try { //查看这个路径是否存在, //如果并没有这个路径, //创建这个路径 File destDir = new File(path); if (!destDir.exists()) { destDir.mkdirs(); } fOut = new FileOutputStream(path + "/" + FILE_NAME) ; } catch (FileNotFoundException e) { e.printStackTrace(); } //将Bitmap对象写入本地路径中,Unity在去相同的路径来读取这个文件 bitmap.compress(Bitmap.CompressFormat.JPEG, 50, fOut); try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } try { fOut.close(); } catch (IOException e) { e.printStackTrace(); } //发送成功消息到unity里面 //SdkUtil.SendMessageOpenPhoto(FILE_NAME); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != NONE) { // 返回的路径 if (requestCode == PHOTOHRAPH) { //查看图片路径 File picture = new File(Environment.getExternalStorageDirectory() + "/temp.jpg"); startPhotoZoom(Uri.fromFile(picture)); } if (data == null) return; // ? ?? if (requestCode == PHOTOZOOM) { startPhotoZoom(data.getData()); } // if (requestCode == PHOTORESOULT) { Bundle extras = data.getExtras(); if (extras != null) { Bitmap photo = extras.getParcelable("data"); try { SaveBitmap(photo); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } super.onActivityResult(requestCode, resultCode, data); }
  • 相关阅读:
    http 事务
    URI、URL、URN
    媒体类型(MIME类型)
    资源
    WEB客户端和服务器
    如何解决新浪微博返回结果中的中文编码问题
    新浪微博 使用OAuth2.0调用API
    新浪微博 授权机制研究
    hmac库 密钥相关的哈希运算消息认证码
    ValueError: Expecting property name: line 1 column 1 (char 1)
  • 原文地址:https://www.cnblogs.com/bambomtan/p/4761033.html
Copyright © 2011-2022 走看看