游戏王中国 2022-08-17 15:35 采纳率: 53.3%
浏览 96
已结题

安卓拍照功能和相册浏览功能

xamarin 拍照功能和相册浏览功能
根据路径获取图片失败 Bitmap resizedBitmap = BitmapFactory.DecodeFile( fileName, options);

操作环境、软件版本等信息
   SetContentView(Resource.Layout.jx_main);
            // Create your application here
            //其他安卓芯片的默认拍照路径
            originalFile = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(
                Android.OS.Environment.DirectoryPictures
                ), "zcb_pic_" + SystemClock.CurrentThreadTimeMillis() + ".jpg");

            //高通芯片的默认拍照路径
            finalFile = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(
                Android.OS.Environment.DirectoryDcim + @"/Camera"
                ), "zcb_pic_" + SystemClock.CurrentThreadTimeMillis() + ".jpg");

//拍照路径
public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
        {
            // First we get the the dimensions of the file on disk
            BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
            BitmapFactory.DecodeFile(fileName, options);

            // Next we calculate the ratio that we need to resize the image by
            // in order to fit the requested dimensions.
            int outHeight = options.OutHeight;
            int outWidth = options.OutWidth;
            int inSampleSize = 1;

            if (outHeight > height || outWidth > width)
            {
                inSampleSize = outWidth > outHeight
                                   ? outHeight / height
                                   : outWidth / width;
            }

            // Now we will load the image and have BitmapFactory resize it for us.
            options.InSampleSize = inSampleSize;
            options.InJustDecodeBounds = false;
            Bitmap resizedBitmap = BitmapFactory.DecodeFile( fileName, options);
            //Bitmap resizedBitmap = BitmapFactory.DecodeFile("file://" + fileName, options);
            return resizedBitmap;
        }



Bitmap resizedBitmap = BitmapFactory.DecodeFile( fileName, options);
如何修改改进

img

img

查考资料

img

  • 写回答

3条回答 默认 最新

  • Orion-W 2022-08-18 08:55
    关注

    1、权限问题
    2、路径问题

    评论

报告相同问题?

问题事件

  • 系统已结题 8月25日
  • 修改了问题 8月19日
  • 赞助了问题酬金10元 8月17日
  • 修改了问题 8月17日
  • 展开全部

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大