//实例化选择器
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 编程

    error播放出错提示音 errorPromptVoice() 返回一个字符串,其中包含从某个字符串右端开始的指定数量的字符 Microsoft.VisualBasic.Right(strBt45Te ...

  2. extjs动态改变样式

    { width:438, height:440, name:'loginDiv', ui:'123', x: '50%' , y: 200, border:true, bodyStyle:{ 'bor ...

  3. jQuery操作checkbox实例

    示意图 <script type="text/javascript"> $(function () { $("#ddlNumber").change ...

  4. java导出生成word

    最近做的项目,需要将一些信息导出到word中.在网上找了好多解决方案,现在将这几天的总结分享一下. 目前来看,java导出word大致有6种解决方案: 1:Jacob是Java-COM Bridge的 ...

  5. c#之Insert字符串的三种写法

    1.Format Format(String, Object) 将指定字符串中的一个或多个格式项替换为指定对象的字符串表示形式. ex1:简单示例怎么应用 private void btnTest_C ...

  6. struts2类型转换器、 类型转换错误 以及INPUT view

    1.1.1    Struts2中的类型转换器 Struts2内置了常见数据类型多种转换器 boolean 和 Boolean char和 Character int 和 Integer long 和 ...

  7. The Imitation Game

    <The Imitation Game>是一部非常好的电影,讲述了人工智能之父——阿兰图灵的传奇一生. 重点讲述了他通过破译德国的通讯密码缩短了二战的持续时间,因而拯救了无数生命的伟大事迹 ...

  8. ios CoreData NSManagedObject 生命周期

    用同样的检索条件从context检索出的对象是一个????所以 在主页的3个brand没法释放,在仅仅处理brand的时候???? 和 多个 context无关 我重写了NSManagedObject ...

  9. PHP生命周期

    2015-08-19 15:05:30 周三 一篇很好的文章 PHP内核探索 总结一下 1. 模块初始化 MINIT 各个PHP模块/扩展初始化内部变量, 告诉PHP调用自己的函数时, 函数体在哪里( ...

  10. [转]AndroidStudio导出jar包

    原文链接:http://blog.csdn.net/hjq842382134/article/details/38538097# 1. 不像在Eclipse,可以直接导出jar包.AndroidStu ...