//实例化选择器
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. vb.net 控件(包括字体)随窗体按比例缩放

    Public Class frmDl Dim x As Single = 0 Dim y As Single = 0 Private Sub frmDl_Load(ByVal sender As Sy ...

  2. BOM基础部分

    打开.关闭窗口 •open –蓝色理想运行代码功能 •close –关闭时提示问题   常用属性 •window.navigator.userAgent •window.location   窗口尺寸 ...

  3. iOS学习笔记(2)--Xcode6.1创建仅xib文件无storyboard的hello world应用

    http://www.mamicode.com/info-detail-514151.html 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载原理很重要 ...

  4. Git索引

    原文: http://gitbook.liuhui998.com/7_4.html git中的索引(index)是一个存放了排好序的路径的二进制文件(通常是.git/index), 每一个条目都附带有 ...

  5. java 调用webservice的各种方法总结

    java 调用webservice的各种方法总结 几种流行的开源WebService框架Axis1,Axis2,Xfire,CXF,JWS比较 方法一:创建基于JAX-WS的webservice(包括 ...

  6. MQTT V3.1----publish解读

    客户端/服务器的发布消息行为,与PUBLISH相关的消息类型: PUBLISH 客户端发布消息经由服务器分发到所有对应的订阅者那里.一个订阅者可以订阅若干个主题(Topic name),但一个PUBL ...

  7. C#错误之 System.Threading.ThreadAbortException:正在中止线程

    参考:http://www.cnblogs.com/chendaoyin/archive/2013/06/27/3159211.html 1.开启一个子线程 //开启一个子线程,子线程调用方法 Met ...

  8. java切换VPN让你像幽灵一样出现在全国各地

    在很多情况下,有些网络应用的需求会要求模拟人在不同地区访问网站和应用.因而切换IP也就应运而生了,然而IP作为一种稀缺资源不是随便可以获得的.因而会想到应用程序切换VPN来达到全国不同地区访问网络.因 ...

  9. Unity3d《Shader篇》法线贴图

    效果图 贴图 法线贴图 //代码 Shader "Custom/NormalMap" { Properties { _MainTex ("Texture", 2 ...

  10. 使用php脚本查看已开启的扩展

    php安装时会将扩展包编译进去,对于一个正在运行中的数据库,查看php的扩展开启状况,第一种方式是通过配置文件查看,另外是通过phpinfo函数查看所有的配置,另外是使用php内置函数来查看,通过脚本 ...