1

嗨,我用本地数据库开发了一个 Windows 手机应用程序,这是我数据库中的一个表

[Table]
    public class DBannotation 
    {
        [Column(IsPrimaryKey = true, CanBeNull = false )]
        public string annotguid { get; set; }
        [Column(IsPrimaryKey = true, CanBeNull = false)]
        public int foruserid { get; set; }
        [Column]
        public int annversion { get; set; }
        [Column]
        public string chapath { get; set; }

}

我必须将图像插入数据库,但我不知道该怎么做我必须添加什么类型的列提前感谢您的帮助提前感谢您的帮助

4

2 回答 2

0

You should store the images in the Isolated Storage, and to avoid conflict of naming the images, you should use GUID to name the images. And of course in your table, you save that GUID.

public static string SaveImage(Stream imageStream, int orientation, int quality)
{
    var fileName = Guid.NewGuid().ToString();
    using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (isolatedStorage.FileExists(fileName))
            isolatedStorage.DeleteFile(fileName);

        IsolatedStorageFileStream fileStream = isolatedStorage.CreateFile(fileName);
        BitmapImage bitmap = new BitmapImage();
        bitmap.SetSource(imageStream);

        WriteableBitmap wb = new WriteableBitmap(bitmap);
        wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, orientation, quality);
        fileStream.Close();
    }
    return fileName;
}
于 2013-05-17T10:19:59.133 回答
-1

在表中:[Column] public byte[] Image { get; 放; }

xml:

<Image Source="{Binding Image, Converter={StaticResource BytesToImageConverter}}"....>



 public class BytesToImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {

            byte[] bytes = value as byte[];
            if (bytes == null) return null;

            BitmapImage image = new BitmapImage();
            SetSource(bytes, image);
            return image;

        }

        private async static void SetSource(byte[] source, BitmapImage image)
        {
            var stream = await Utils.ToRandomAccessStream(source);
            await image.SetSourceAsync(stream);
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    } 
于 2013-05-17T11:00:35.987 回答