标签:fp SQLite byte Image item new bit 存取 求教
原文链接:http://www.cnblogs.com/htfucc/archive/2012/08/02/2620521.html我最近刚开始研究WP7,在用SQLite存取图片时遇到个问题,希望高手们指点。
图片转换成二进制存到SQLite时是 byte[14361],读出来时却成了byte[13],数据库里图片存储格式是Blob。Why?
这是我的代码:
//把图片转换成二进制存入sqlite private byte[] SetPicture() { BitmapImage bit = new BitmapImage(new Uri("image.jpg", UriKind.Relative)); Image image = new Image(); image.Source = bit; this.image1.Source = bit; WriteableBitmap bmp = new WriteableBitmap(image.Source as BitmapSource); byte[] byteArray; using (MemoryStream stream = new MemoryStream()) { bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100); byteArray = stream.ToArray(); } return byteArray; }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { SQLiteConnection mySqliteDB = new SQLiteConnection("SQLiteDB"); mySqliteDB.Open(); SQLiteCommand cmd = mySqliteDB.CreateCommand("select*from FriendTable"); IEnumerable<Friend> list = cmd.ExecuteQuery<Friend>(); List<FriendPct> listfd = new List<FriendPct>(); foreach(Friend item in list.ToList()) { FriendPct fp = new FriendPct(); fp.ID = item.ID; fp.Name=item.Name; fp.Phone = item.Phone; fp.Picture = GetPath(item.Picture); fp.Class = item.Class; fp.Firsttime = item.Firsttime; fp.Lasttime = item.Lasttime; fp.Callcount = item.Callcount; fp.Grade = item.Grade; fp.Popcount = item.Popcount; listfd.Add(fp); } this.Files.ItemsSource = listfd; } //二进制数组转图片 public static Image GetPath(byte[] b) { try { BitmapImage bit = new BitmapImage(); Stream ms = new MemoryStream(b); bit.SetSource(ms); Image img = new Image(); img.Source = bit; ms.Flush(); ms.Close(); return img; } catch (Exception ex) { return null; } }
上面IEnumerable<Friend> list。。。。list中返回的Picture为什么是byte[13]呢?
转载于:https://www.cnblogs.com/htfucc/archive/2012/08/02/2620521.html
标签:fp,SQLite,byte,Image,item,new,bit,存取,求教 来源: https://blog.csdn.net/weixin_30733003/article/details/97736450
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。