//实例化选择器
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()) != 0)
{
newPixelHeight = int.Parse(textBox2.Text.ToString());
}
}
void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
if (textBox1.Text != "" && int.Parse(textBox1.Text.ToString()) != 0)
{
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, 0, 85);
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(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;
}
}
"LayoutRoot" Background="Transparent">
Auto"/>
*"/>
"TitlePanel" Grid.Row="0" Margin="12,17,0,28">
"ApplicationTitle" Text="MY APPLICATION" color: #800000;">"{StaticResource PhoneTextNormalStyle}"/>
"PageTitle" Text="page name" Margin="9,-7,0,0" color: #800000;">"{StaticResource PhoneTextTitle1Style}"/>
"ContentPanel" Grid.Row="1" Margin="12,0,12,0">
"img" 300" VerticalAlignment="Top" />