Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by qwerr ( 13 years ago )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using PhoneApp3.ServiceReference1;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
using System.IO;
namespace PhoneApp3
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
byte[] _imageBuffer = null;
public MainPage()
{
InitializeComponent();
}
private void btnTakePhoto_Click(object sender, RoutedEventArgs e)
{
CameraCaptureTask task = new CameraCaptureTask();
task.Completed += (s, evt) =>
{
if (evt.Error == null && evt.TaskResult == TaskResult.OK)
{
_imageBuffer = new byte[evt.ChosenPhoto.Length];
evt.ChosenPhoto.Read(_imageBuffer, 0, Convert.ToInt32(evt.ChosenPhoto.Length)); BitmapImage bmpImage = new BitmapImage();
bmpImage.SetSource(evt.ChosenPhoto);
imgPreview.Source = bmpImage;
}
};
task.Show();
}
private void btnUploadPhoto_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client client = new Service1Client();
// WcfServiceClient client = new WcfServiceClient();
// client.UploadCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_UploadCompleted);
// client.intoAsync(txtFullName.Text);
//if (_imageBuffer != null)
//{
// client.UploadAsync(p
// client.OpenAsync();
PictureFile picFile = new PictureFile();
picFile.PictureName = txtFullName.Text;
picFile.PictureStream = _imageBuffer;
// client.UploadAsync(picFile);
client.putAsync(picFile);
// client.CloseAsync();
//}
//else
//{
// MessageBox.Show("Please take a picture first !!!");
//}
}
//void client_UploadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
//{
// throw new NotImplementedException();
//}
//void client_UploadCompleted(object sender, UploadCompletedEventArgs e)
//{
// if (e.Error == null)
// {
// if (e.Result)
// {
// lblOperationStatus.Text = "Upload succeeded :)";
// }
// else
// {
// lblOperationStatus.Text = "Upload failed :(";
// }
// }
// else
// {
// lblOperationStatus.Text = e.Error.Message;
// }
//}
private void btnGetPhoto_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client client = new Service1Client();
client.DownloadCompleted += new EventHandler<DownloadCompletedEventArgs>(client_DownloadCompleted);
//if (txtFullName.Text.Trim().Length == 0)
//{
// MessageBox.Show("Please enter Voter's Name");
//}
//else
//{
client.OpenAsync();
client.DownloadAsync(Convert.ToInt32(textBox1.Text));
client.CloseAsync();
//}
}
void client_DownloadCompleted(object sender, DownloadCompletedEventArgs e)
{
BitmapImage bitmapImage = new BitmapImage();
if (e.Error == null)
{
if (e.Result.PictureStream != null)
{
PictureFile picture = e.Result;
MemoryStream stream = new MemoryStream(picture.PictureStream);
bitmapImage.SetSource(stream);
imgPreview.Source = bitmapImage;
lblOperationStatus.Text = "Image Downloaded and shown...";
}
else
{
lblOperationStatus.Text = "No image with that name exists";
}
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client o = new Service1Client();
o.getdiscAsync(Convert.ToInt32(textBox1.Text));
o.getdiscCompleted += new EventHandler<getdiscCompletedEventArgs>(o_getdiscCompleted);
}
void o_getdiscCompleted(object sender, getdiscCompletedEventArgs e)
{
BitmapImage bitmapImage = new BitmapImage();
PictureFile pic=new PictureFile();
var a = e.Result;
foreach (var d in a)
{
txtFullName.Text = d.FullName;
// imgPreview.Source = d.Image;
MemoryStream stream = new MemoryStream(pic.PictureStream);
//bitmapImage.SetSource(d.Image);
//imgPreview.Source = bitmapImage;
//PictureFile picture = d.Image;
//MemoryStream stream = new MemoryStream(picture.PictureStream);
//bitmapImage.SetSource(stream);
//imgPreview.Source = bitmapImage;
}
}
}
}
Revise this Paste