잃고 있어요 내가 뭘 잘못하고 있니?컴파일러가 WP7에서 JpegBitmapEncoder 클래스를 찾을 수 없습니다
Error 3 The name 'BitmapFrame' does not exist in the current context
Error 2 The type or namespace name 'JpegBitmapEncoder' could not be found (are you missing a using directive or an assembly reference?)
코드 : WP7에
namespace Microsoft.Samples.CRUDSqlAzure.Phone.Converters
{
using System;
using System.Windows.Data;
using System.IO;
using System.Windows.Media.Imaging;
public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
byte[] rawImageBytes = (byte[])value;
BitmapImage imageSource = null;
try
{
using (MemoryStream stream = new MemoryStream(rawImageBytes))
{
stream.Seek(0, SeekOrigin.Begin);
BitmapImage b = new BitmapImage();
b.SetSource(stream);
imageSource = b;
}
return imageSource;
}
catch
{
return null;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
BitmapImage bitmapImage = (BitmapImage)value;
byte[] data;
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
using (MemoryStream ms = new MemoryStream())
{
encoder.Save(ms);
data = ms.ToArray();
}
return data;
}
catch
{
return null;
}
}
}
}
감사합니다. 내 xaml 페이지의 ''요소에 바인딩하려고합니다. 나는 바이트 []에 데이터를 저장 으로이 변환기를 사용해야합니다 –
Michael
난 아직도 당신이 뭘 하려는지 완전히 이해가 안 돼요. 그래서 당신은 당신의 이미지를 바이트 배열로 저장해야합니다 ... 글쎄요, 모든 것이 바이트 배열로 저장되므로 괜찮습니다. 당신은 이미지 컨트롤에 바인딩하고 싶습니다. 바이트 배열을 ImageSource로 변환하려면 변환기를 사용해야합니다. 그런데 왜 다시 변환해야합니까? –
좋은 점은 실제로 생각하면, 데이터베이스에서 앱을 읽을 때 바이트 배열을 imagesource로 변환해야 할 때, 전화 카메라로 사진을 찍고 db로 저장하면 imagesource에서 이미지를 변환해야합니다. 바이트 배열. – Michael