//实例化选择器
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. sql server 2008笔记

    sql server 2008开启远程访问数据库 1.以windows验证模式进入数据库管理器. 第二步:右击sa,选择属性: 在常规选项卡中,重新填写密码和确认密码(改成个好记的).把强制实施密码策 ...

  2. css position属性

    absolute, 屏幕为参照, 但固定在页面上,随页面滚动而动. fixed, 父元素没有指定position属性(或position属性为static时)==>屏幕为参照,固定在屏幕的某个位 ...

  3. (转) C#如何使用异步编程

    怎么使用异步,就是用委托进行处理,如果委托对象在调用列表中只有一个方法,它就可以异步执行这个方法.委托类有两个方法,叫做BeginInvoke和EndInvoke,它们是用来异步执行使用. 异步有三种 ...

  4. SQL merge into 表合并

    Merge关键字是一个神奇的DML关键字.它在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句.MSDN对于Merge的解释非常的短小精悍:”根据与源 ...

  5. iOS 活动图 流程图

    活动图        活动图和状态机图都被称为演化图,其区别和联系如下:       1.活动图:用于描述用例内部的活动或方法的流程,如果除去活动图中的并行活动描述以后,它就变成流程图.       ...

  6. php empty()和isset()

    2015年12月11日 10:59:08 echo phpversion(); //5.6.13 $a = array( 'aaa' => 1, 'bbb' => 0, 'ccc' =&g ...

  7. 1.JS设计模式-this,call&apply

    1. this,call&apply 1.1 this this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用. 1.1.1 普通函数调 ...

  8. js数组转置

    <script type="text/javascript">     var arr=[[1,2,3],[4,5,6],[7,8,9],[17,18,19]];    ...

  9. ABAP 内表的行列转换-NEW

    REPORT Z_TEST_COL_TO_ROW. TYPE-POOLS: slis. TABLES: mseg,mkpf. DATA: gd_fieldcat TYPE slis_t_fieldca ...

  10. CentOS7 win7 u盘装双系统 修复系统

    环境: ASUS MB VER K45VD 笔记本电脑一台( i5-3230M 处理器. SATA . Nvidia). Windows7 系统 在 win7 下安装 CentOS7 使用 Ultra ...