第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用我制作的應(yīng)用程序?qū)D像保存到圖庫(kù)?

如何使用我制作的應(yīng)用程序?qū)D像保存到圖庫(kù)?

Go
人到中年有點(diǎn)甜 2022-11-21 20:06:16
我有這個(gè)Xamarin Android 應(yīng)用程序(不是 Forms),它可以打開(kāi)相機(jī)并讓我拍照并隨拍或拍一張新照片。之后,ImageView使用位圖向我展示應(yīng)用程序上的圖片。我無(wú)法使用位圖保存到畫(huà)廊(我不知道該怎么做,或者是否有更簡(jiǎn)單的方法)。我需要應(yīng)用程序獲取應(yīng)用程序拍攝的最后一張照片(為什么需要保存它)并通過(guò)單擊按鈕將其發(fā)送到服務(wù)器(我也需要一些幫助)。這就是我需要做的。這是代碼MainActivity.cs:using Android.App;using Android.Widget;using Android.OS;using Android.Content;using Android.Provider;using Android.Runtime;using Android.Graphics;namespace CameraApp{    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]    public class MainActivity : Activity    {        ImageView imageView;        protected override void OnCreate(Bundle bundle)        {            base.OnCreate(bundle);            SetContentView(Resource.Layout.activity_main);            Button btnCamera = FindViewById<Button>(Resource.Id.btnCamera);            imageView = FindViewById<ImageView>(Resource.Id.imageView);            btnCamera.Click += BtnCamera_Click;        }        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)        {            base.OnActivityResult(requestCode, resultCode, data);            Bitmap bitmap = (Bitmap)data.Extras.Get("data");            imageView.SetImageBitmap(bitmap);        }        private void BtnCamera_Click(object sender, System.EventArgs e)        {            Intent intent = new Intent(MediaStore.ActionImageCapture);            StartActivityForResult(intent, 0);        }    }}
查看完整描述

2 回答

?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊

我寫(xiě)了一個(gè)關(guān)于你的需求的演示。我添加了相機(jī)和外部存儲(chǔ)權(quán)限并將圖像存儲(chǔ)到畫(huà)廊,這里正在運(yùn)行 GIF。

https://i.stack.imgur.com/FPLUY.gif

有運(yùn)行demo的代碼。我添加了運(yùn)行時(shí)權(quán)限(相機(jī)和WriteExternalStorage)請(qǐng)求。并判斷用戶沒(méi)有拍照的情況,然后返回應(yīng)用程序。


[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]

public class MainActivity : AppCompatActivity, ActivityCompat.IOnRequestPermissionsResultCallback

{

    Button button1;

    ImageView imageView1;

    View layout;

    static readonly int REQUEST_CAMERA_WriteExternalStorage = 0;


    protected override void OnCreate(Bundle savedInstanceState)

    {

        base.OnCreate(savedInstanceState);

        // Set our view from the "main" layout resource

        SetContentView(Resource.Layout.activity_main);

        layout = FindViewById<RelativeLayout>(Resource.Id.sample_main_layout);

        button1 = FindViewById<Button>(Resource.Id.button1);

        imageView1 = FindViewById<ImageView>(Resource.Id.imageView1);

        button1.Click += (o, e) =>

        {

            CheckPermission();

        };

    }



    public  void CheckPermission()

    {

        if ((ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == (int)Permission.Granted)&& (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == (int)Permission.Granted))

        {

            // Camera and store permission has  been granted

            ShowCamera();

        }

        else

        {

            // Camera and store permission has not been granted

            RequestPermission();


        }



    }


    private void RequestPermission()

    {


        ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage }, REQUEST_CAMERA_WriteExternalStorage);


    }



    //get result of persmissions

    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)

    {

        if (requestCode == REQUEST_CAMERA_WriteExternalStorage)

        {



            if ( PermissionUtil.VerifyPermissions(grantResults))

            {

                // All required permissions have been granted, display Camera.


                ShowCamera();

            }

            else

            {

                // permissions did not grant, push up a snackbar to notificate USERS

                Snackbar.Make(layout, Resource.String.permissions_not_granted, Snackbar.LengthShort).Show();

            }


        }

        else

        {

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);

        }

    }


    private void ShowCamera()

    {

        Intent intent = new Intent(MediaStore.ActionImageCapture);

        StartActivityForResult(intent, 0);

    }



    protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)

    {

        base.OnActivityResult(requestCode, resultCode, data);

        Bitmap bitmap=null;

        //If user did not take a photeo , he will get result of bitmap, it is null

        try {

             bitmap = (Bitmap)data.Extras.Get("data");

        } catch(Exception e)

        {

            Log.Error("TakePhotoDemo1", e.Message);

            Toast.MakeText(this, "You did not take a photo", ToastLength.Short).Show();


        }


        if (bitmap != null)

        {

            MediaStore.Images.Media.InsertImage(ContentResolver, bitmap, "screen", "shot");

            imageView1.SetImageBitmap(bitmap);

        }

        else

        {

            Toast.MakeText(this, "You did not take a photo", ToastLength.Short).Show();

        }


    }


}

PermissionUtil.cs通過(guò)驗(yàn)證給定數(shù)組中的每個(gè)條目是否具有值 Permission.Granted,檢查是否已授予所有給定權(quán)限。


   public abstract class PermissionUtil

{


    public static bool VerifyPermissions(Permission[] grantResults)

    {

        // At least one result must be checked.

        if (grantResults.Length < 1)

            return false;


        // Verify that each required permission has been granted, otherwise return false.

        foreach (Permission result in grantResults)

        {

            if (result != Permission.Granted)

            {

                return false;

            }

        }

        return true;

    }

}

有我的代碼。


https://github.com/851265601/TakePhotoDemo1


MediaStore.Images.Media.InsertImage前面的代碼將在 gallery( )的末尾添加圖像。如果您想修改日期以使其出現(xiàn)在開(kāi)頭或任何其他元數(shù)據(jù)中,請(qǐng)參閱此鏈接。 https://gist.github.com/samkirton/0242ba81d7ca00b475b9


查看完整回答
反對(duì) 回復(fù) 2022-11-21
?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊

您可以通過(guò) MediaStore 插入圖像

MediaStore.Images.Media.InsertImage(this, yourBitmap, yourTitle, yourDescription);

注意:您可能想為此添加寫(xiě)入外部存儲(chǔ)權(quán)限。


查看完整回答
反對(duì) 回復(fù) 2022-11-21
  • 2 回答
  • 0 關(guān)注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)