//实例化选择器
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
BitmapImage bimg;
int newPixelWidth;
int newPixelHeight; //构造函数里 //从页面读取输入值作为目标分辨率
newPixelHeight = int.Parse(textBox2.Text.ToString());
//从页面读取输入值作为目标分辨率
newPixelHeight = int.Parse(textBox2.Text.ToString());
newPixelWidth = int.Parse(textBox1.Text.ToString()); textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged);
textBox2.TextChanged += new TextChangedEventHandler(textBox2_TextChanged); void textBox2_TextChanged(object sender, TextChangedEventArgs e)
{
if (textBox2.Text != "" && int.Parse(textBox2.Text.ToString()) != )
{
newPixelHeight = int.Parse(textBox2.Text.ToString());
}
} void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
if (textBox1.Text != "" && int.Parse(textBox1.Text.ToString()) != )
{
newPixelWidth = int.Parse(textBox1.Text.ToString());
}
} private void button1_Click(object sender, RoutedEventArgs e)
{
//为JPEG文件创建一个流
StreamResourceInfo sri = null; //将Tulips.jpg的Build Action设为Content
Uri jpegUri = new Uri("Images/Tulips.jpg", UriKind.Relative);
sri = Application.GetResourceStream(jpegUri); //将该流解码
WriteableBitmap bitmap = PictureDecoder.DecodeJpeg(sri.Stream);
img.Source = bitmap;
} private void button2_Click(object sender, RoutedEventArgs e)
{
String tempjpg = "tempimg"; //创建虚拟存储
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(tempjpg))
{
myStore.DeleteFile(tempjpg);
} IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempjpg);
StreamResourceInfo sri = null;
sri = Application.GetResourceStream(new Uri("Images/Tulips.jpg", UriKind.Relative)); //创建WriteableBitmap对象,
BitmapImage bitmap = new BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.None;
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap); //WriteableBitmap对象编码,设置目标分辨率
wb.SaveJpeg(myFileStream, newPixelWidth, newPixelHeight, , );
myFileStream.Close(); myFileStream = myStore.OpenFile(tempjpg, FileMode.Open, FileAccess.Read); //保存图片到图片库
MediaLibrary library = new MediaLibrary();
Picture pic = library.SavePicture("SavedPicture.jpg", myFileStream); myFileStream.Close();
} private void button3_Click(object sender, RoutedEventArgs e)
{
//打开图片库
photoChooserTask.Show();
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed); } void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
bimg = new BitmapImage();
bimg.SetSource(e.ChosenPhoto);
//设置Image控件的数据源
img.Source = bimg;
}
}

UI

    <Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel> <!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="" Margin="12,0,12,0">
<Image x:Name="img" Height="" VerticalAlignment="Top" />
<Button Content="加载图片" Height="" HorizontalAlignment="Left" Margin="150,0,0,219" Name="button1" VerticalAlignment="Bottom" Width="" Click="button1_Click" />
<Button Content="保存图片" Height="" HorizontalAlignment="Left" Margin="150,376,0,0" Name="button2" VerticalAlignment="Top" Width="" Click="button2_Click" />
<Button Content="查看图片" Height="" HorizontalAlignment="Left" Margin="150,438,0,0" Name="button3" VerticalAlignment="Top" Width="" Click="button3_Click" />
<TextBox Height="" HorizontalAlignment="Left" Margin="150,535,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="" />
<TextBox Height="" HorizontalAlignment="Left" Margin="251,535,0,0" Name="textBox2" Text="" VerticalAlignment="Top" Width="" />
<TextBlock Height="" HorizontalAlignment="Left" Margin="-12,555,0,0" Name="textBlock1" Text="设置目标分辨率" VerticalAlignment="Top" Width="" />
</Grid>
</Grid>

wp8 入门到精通 ImageCompress 图片压缩的更多相关文章

  1. wp8 入门到精通 Gallery

    <Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.Resources> ...

  2. wp8 入门到精通 启动系统分享照片任务

    PhotoChooserTask photoChooserTask = new PhotoChooserTask(); photoChooserTask.Completed += photoChoos ...

  3. wp8 入门到精通 虚拟标示符 设备ID

    //获得设备虚拟标示符 wp8 public string GetWindowsLiveAnonymousID() { object anid = new object(); string anony ...

  4. wp8 入门到精通 仿美拍评论黑白列表思路

    static bool isbool = false; private void BindGameDelete() { Tile tile = new Tile(); List<Color> ...

  5. wp8 入门到精通 生命周期

  6. wp8 入门到精通 定时更新瓷贴

    public class ScheduledAgent : ScheduledTaskAgent { static ScheduledAgent() { Deployment.Current.Disp ...

  7. wp8 入门到精通 MultiMsgPrompt

    List<NotifyMsg> arraymsg = new List<NotifyMsg>(); List<NotifyInfo> ArrayNotifyInfo ...

  8. wp8 入门到精通 数据库更新字段(一)

    public class UserInfoDB : BaseDB { public UserInfoDB() : base(@"Data Source=isostore:\MakeLove\ ...

  9. wp8 入门到精通 Utilities类 本地存储+异步

    public class CCSetting { public async static void AddOrUpdateValue<T>(string key, T value) { t ...

随机推荐

  1. python对象的生命周期

    引言 碰到以下问题: 代码1: from Tkinter import * root = Tk() photo = PhotoImage(file=r'E:\workspace\python\111. ...

  2. 《Head First Servlet JSP》web服务器,容器,servlet的职责

    (一)web服务器,容器,servlet的职责 (二)J2EE服务器与web容器

  3. oracle数据库两表数据比较

    本文转自http://blog.sina.com.cn/s/blog_3ff4e1ad0100tdl2.html 1 引言 在程序设计的过程中,往往会遇到两个记录集的比较.如华东电网PMS接口中实现传 ...

  4. Linux安装字体

    用惯了Win7的字体,感觉雅黑看着很舒服,就动手在Linux安装下,简单描述下: 第一步:百度一下,找到微软雅黑字体(.ttf)下载 第二步:把下载的字体放到cd /usr/share/fonts/z ...

  5. ubuntu14.04和win7共享文件夹

    环境:vmware12 问题:安装了vmware-tools,但是在/mnt/hgfs下面看不到共享的文件夹. 按照网上的一些经验和教程使用如下命令: mount -t vmhgfs .host:/ ...

  6. 5.nodejs权威指南--HTTP

    1. HTTP 1.1 服务器 var http = require('http'); var server = http.createServer(function(req,rsp){ req.on ...

  7. Divide and conquer:4 Values whose Sum is 0(POJ 2785)

    找四个数的和为0 题目大意:给定四个集合,要你每个集合选4个数字,组成和为0 这题是3977的简单版,只要和是0就可以了 #include <iostream> #include < ...

  8. ssm控制输出sql(二)

    望时高科联通log4j # DEBUG,INFO,WARN,ERROR,FATAL LOG_LEVEL=DEBUG ---------这里对应sql的级别 log4j.rootLogger=${LOG ...

  9. SQL Server 子查询

    这些主要是老师上课讲的一些知识点,自己做了一些整理放在这里~~~ 子查询可以是标量的.多值的或是表值的. 在期待单个值的地方可以使用标量子查询.例如,以下查询返回具有最大员工编号的员工信息: SELE ...

  10. 【编程之美】2.5 寻找最大的k个数

    有若干个互不相等的无序的数,怎么选出其中最大的k个数. 我自己的方案:因为学过找第k大数的O(N)算法,所以第一反应就是找第K大的数.然后把所有大于等于第k大的数取出来. 写这个知道算法的代码都花了2 ...