axml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><Button      android:id="@+id/btn0"    android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="从相册中选择照片"    />  <Button    android:id="@+id/btn1"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:text="拍照"    />  <ImageView    android:id="@+id/imageID"    android:layout_width="fill_parent"    android:layout_height="wrap_content"            /></LinearLayout>

C#

using System;using Android.App;using Android.Content;using Android.Widget;using Android.OS;using Android.Graphics;using System.IO;namespace Phoot{    [Activity(Label = "Phoot", MainLauncher = true, Icon = "@drawable/icon")]    public class Activity1 : Activity    {        public static int NONE = 0;        public static int PHOTOHRAPH = 1;//拍照        public static int PHOTOXZOOM = 2;//缩放        public static int PHOTORESOULT = 3;//结果        public static string IMAGE_UNSPECTFIED = "image/*";        ImageView imageview = null;        Button button0 = null;        Button button1 = null;        protected override void OnCreate(Bundle bundle)        {            base.OnCreate(bundle);            // Set our view from the "main" layout resource            SetContentView(Resource.Layout.Main);            button0 = FindViewById<Button>(Resource.Id.btn0);            button1 = FindViewById<Button>(Resource.Id.btn1);            imageview = FindViewById<ImageView>(Resource.Id.imageID);            button0.Click += new EventHandler(button0_Click);            button1.Click += new EventHandler(button1_Click);        }        //选择照片        void button0_Click(object sender, EventArgs e)        {            Intent intent = new Intent(Intent.ActionPick, null);            //选择照片意图            intent.SetDataAndType(             Android.Provider.MediaStore.Images.Media.ExternalContentUri, IMAGE_UNSPECTFIED);            StartActivityForResult(intent, PHOTOXZOOM);        }        //拍照        void button1_Click(object sender, EventArgs e)        {                        Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);            string file = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(),Android.OS.Environment.DirectoryDcim.ToString()+ "/test.jpg");            var outputFileUri = Android.Net.Uri.Parse(file);            intent.PutExtra(Android.Provider.MediaStore.ExtraOutput,file);            StartActivityForResult(intent, PHOTOHRAPH);        }        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)        {            if (requestCode == NONE)            {                return;            }            if (requestCode == PHOTOHRAPH)            {                //获取照片                Bitmap bitmap = (Bitmap)data.Extras.Get("data");                 Java.IO.File picture = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.ToString()+"/"+Android.OS.Environment.DirectoryDcim.ToString() + "/test.jpg");                  //Java.IO.FileOutputStream b = new Java.IO.FileOutputStream(picture);                  FileStream MyFileStream1 = new FileStream(picture.ToString(), FileMode.Create);                //保存照片                  bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, MyFileStream1);                   if (System.IO.File.Exists(picture.ToString()))                {                    startPhotoZoom(Android.Net.Uri.FromFile(picture));                }                                //startPhotoZoom            }            if (data == null)            {                return;            }            if (requestCode == PHOTOXZOOM)            {                startPhotoZoom(data.Data);            }            //处理结果            if (requestCode == PHOTORESOULT)            {                Bundle extras = data.Extras;                if (extras != null)                {                    Bitmap photo = (Bitmap)extras.GetParcelable("data");                                        //Stream stream = null;                    //压缩文件                    //photo.Compress(Bitmap.CompressFormat.Jpeg, 75, stream);                    imageview.SetImageBitmap(photo);                }            }                    base.OnActivityResult(requestCode, resultCode, data);        }               //缩放        public void startPhotoZoom(Android.Net.Uri uri)        {            Intent intent = new Intent("com.android.camera.action.CROP");            intent.SetDataAndType(uri, IMAGE_UNSPECTFIED);            intent.PutExtra("crop", true);            //// aspectX aspectY 是宽高的比例             intent.PutExtra("aspectX", 1);            intent.PutExtra("aspectY", 1);            //// outputX outputY 是裁剪图片宽?             intent.PutExtra("outputX", 100);            intent.PutExtra("outputY", 100);            intent.PutExtra("return-data", true);            StartActivityForResult(intent, PHOTORESOULT);        }    }}


以前的我是没有做笔记的习惯的,学习了后觉得自己能记住,但是最近发现很多学的东西都忘记了,所有现在一有新的知识,就记下来吧。

最近又做一个mono for android 的项目 这次调整比较大,上次做的点餐系统很好用 ,但是做的时候没有做笔记很多东西都忘记了,这次我把项目涉及到的知识传到博客上,方便记忆,也很大家分享分享的,希望大家能给出点意见。——小査

更多相关文章

  1. android多点触摸缩放图片
  2. android imageVIew拖动 && 图片缩放
  3. android 两点缩放图片
  4. android camera照片旋转90度
  5. View组件之各xml属性
  6. Android(安卓)缩放、移动、旋转View相关方法
  7. 三大布局的基本摆放属性总结,以及imageVIew图片摆放的缩放问题
  8. Android(安卓)移动终端camera 防偷*拍设置
  9. Android(安卓)Drawable Resources系列9:

随机推荐

  1. Android 4.0 Graphics and Animations
  2. Android中两个控件滑动效果冲突的解决办
  3. Android(安卓)App异常检测及处理
  4. Android关于OnTouch 和OnClick同时调用冲
  5. 【问题处理】arcgis运行在android studio
  6. android 显示系统时间
  7. Android_build.gradle配置
  8. Android Studio编译出现Error:Execution
  9. android三种载入图片方式
  10. 如何安装,卸载eclipse中的ADT,或者更新ADT