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 的项目 这次调整比较大,上次做的点餐系统很好用 ,但是做的时候没有做笔记很多东西都忘记了,这次我把项目涉及到的知识传到博客上,方便记忆,也很大家分享分享的,希望大家能给出点意见。——小査

mono for android 获取手机照片或拍照并裁剪保存的更多相关文章

  1. 如何兼容所有Android版本选择照片或拍照然后裁剪图片--基于FileProvider和动态权限的实现

    我们知道, Android操作系统一直在进化. 虽然说系统是越来越安全, 可靠, 但是对于开发者而言, 开发难度是越来越大的, 需要注意的兼容性问题, 也越来越多. 就比如在Android平台上拍照或 ...

  2. Android 获取手机信息,设置权限,申请权限,查询联系人,获取手机定位信息

    Android 获取手机信息,设置权限,申请权限,查询联系人,获取手机定位信息 本文目录: 获取手机信息 设置权限 申请权限 查询联系人 获取手机定位信息 调用高德地图,设置显示2个坐标点的位置,以及 ...

  3. android API版本对应的系统版本及Android获取手机和系统版本等信息的代码

    学了这么久的Android,竟然一直对其API对应的名称关系一值搞不清楚,现在网上认真看了下资料,转载一个觉得写得不错的作者的文章,记下来: [背景] 之前折腾android期间,慢慢地知道了,And ...

  4. Android 获取手机的厂商、型号、Android系统版本号等工具类(转载)

    Android 获取手机的厂商.型号.Android系统版本号等工具类 1.获取手机制造厂商 2.获取手机型号 3.获取手机系统当前使用的语言 4.获取Android系统版本号 5.获取手机IMEI串 ...

  5. Android 获取手机Mac地址,手机名称

    /** * 获取手机mac地址<br/> * 错误返回12个0 */ public static String getMacAddress(Context context) { // 获取 ...

  6. android获取手机信息大全

    IMEI号,IESI号,手机型号: private void getInfo() { TelephonyManager mTm = (TelephonyManager) getSystemServic ...

  7. Android获取手机制作商,系统版本等

    在开发中 我们有时候会需要获取当前手机的系统版本来进行判断,或者需要获取一些当前手机的硬件信息. android.os.Build类中.包括了这样的一些信息.我们可以直接调用 而不需要添加任何的权限和 ...

  8. Android获取手机设备识别码(IMEI)和手机号码

    最近看了下获取手机设备ID和手机信息以及SIM的信息例子,主要还是借鉴别人的,现在自己写一下,算是巩固加深了,也希望能给大家一个参考 必要的条件还是一部真机,SIM卡或者UIM卡. 首先,在Andro ...

  9. android获取手机信息2

    IMEI号,IESI号,手机型号: private void getInfo() { TelephonyManager mTm = (TelephonyManager) getSystemServic ...

随机推荐

  1. Security Policy:行级安全(Row-Level Security)

    行级安全RLS(Row-Level Security)是在数据行级别上控制用户的访问,控制用户只能访问数据库表的特定数据行.断言是逻辑表达式,在SQL Server 2016中,RLS是基于安全断言( ...

  2. MyBatis基础入门--知识点总结

    对原生态jdbc程序的问题总结 下面是一个传统的jdbc连接oracle数据库的标准代码: public static void main(String[] args) throws Exceptio ...

  3. SharpMap简析

    1.背景 因为项目需求,需要基于开源项目来对SHP进行相关操作.涉及到的主要功能就是加载SHP读取其中的属性信息和几何信息.于是选择了Sharpmap来进行,在使用中对其相关功能做了初步了解,做个总结 ...

  4. C语言动态走迷宫

    曾经用C语言做过的动态走迷宫程序,先分享代码如下: 代码如下: //头文件 #include<stdio.h> #include<windows.h>//Sleep(500)函 ...

  5. 基于Composer Player 模型加载和相关属性设置

    主要是基于达索软件Composer Player.的基础上做些二次开发. public class ComposerToolBarSetting { public bool AntiAliasingO ...

  6. 让你从零开始学会写爬虫的5个教程(Python)

    写爬虫总是非常吸引IT学习者,毕竟光听起来就很酷炫极客,我也知道很多人学完基础知识之后,第一个项目开发就是自己写一个爬虫玩玩. 其实懂了之后,写个爬虫脚本是很简单的,但是对于新手来说却并不是那么容易. ...

  7. java 字节流与字符流的区别

    字节流与和字符流的使用非常相似,两者除了操作代码上的不同之外,是否还有其他的不同呢?实际上字节流在操作时本身不会用到缓冲区(内存),是文件本身直接操作的,而字符流在操作时使用了缓冲区,通过缓冲区再操作 ...

  8. windows10安装mysql5.7.17是这样安装的吗?

    操作 全允许

  9. emmet,jade,haml, slim,less,sass,coffeescript等的实战优缺点

    摘要: 文章背景,来自于群内周五晚上的一次头脑风暴式的思维碰撞交流活动. 随着前端技术的蓬勃发展, 各种新技术随着生产力的需要不断的涌入我们的视野, 那今天探讨的话题是这些新时代的前端兵器谱: 一. ...

  10. 我正在使用Xamarin的跨平台框架—Xamarin.Android回忆录

    一.缘起 在自己给别家公司做兼职外包的时候,已经明确知道外包的活不是那么好干的,一般在经历了初期热血澎湃的激情后,逐渐冷淡,愤怒,再冷淡,再愤怒…,听上去好像高潮迭起,但令人尴尬的是,这高潮迭起我们都 ...