|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Question about ObservableCollection and imagesThanks in advance, Marko Vuksanovic. public class PhotosCollection { public static DataSet ds; private DataTable photoDataTable= new DataTable(); private ObservableCollection<Photo> photos = new ObservableCollection<Photo>(); public ObservableCollection<Photo> Photos { get { return this.photos; } } public void GetData() { photoDataTable=ds.Tables["photo"]; photos.Clear(); for (int i = 0; i < photoDataTable.Rows.Count; i++) { photos.Add(new Photo((int)photoDataTable.Rows[i][0], (string)photoDataTable.Rows[i][1], (long)photoDataTable.Rows[i][2], (int)photoDataTable.Rows[i][3], (string)photoDataTable.Rows[i][4], (int)photoDataTable.Rows[i][5], (int)photoDataTable.Rows[i][6], (int)photoDataTable.Rows[i][7])); } } } public class Photo { private int id; private string owner; private long secret; private int server; private string title; private int ispublic; private int isfriend; private int isfamily; private StreamReader photoURL; public Photo(int id, string owner, long secret, int server, string title, int ispublic, int isfriend, int isfamily) { this.id = id; this.owner = owner; this.secret = secret; this.server=server; this.title = title; this.ispublic = ispublic; this.isfriend = isfriend; this.isfamily = isfamily; photoURL= new StreamReader("http://static.flickr.com/"+this.server+"/"+this.id+"_"+this..secret+"_t.jpg"); this.thumbNailPhoto = ImageFromString(photoURL); } public ImageSource ThumbNailPhoto { get { return this.thumbNailPhoto; } ImageSource thumbNailPhoto; public ImageSource ImageFromString(StreamReader url) { BitmapImage image = null; if (url != null) { image = new BitmapImage(); image.BeginInit(); image.StreamSource=new Stream(url); image.EndInit(); } return image; } } Never mind... Figured it out....
"Marko Vuksanovic" <markovuksano***@hotmail.com> wrote in message news:99780F92-2B74-4493-BDBF-9631A539C988@microsoft.com... I am trying to implement an obesrvable collection that a WPF application ca use to generate images. The code I have made by now is shown below: I have the problem with image.StreamSource=new Stream(url)... The "url" is the location of the image which has to be fetched.... but I'm doing something wrong as I cannot load the string itno the stream source. Anyone knows what I am doing wrong? Also if you see any other problems with the code,.. do let me know (as there are, I guess, a lot....)Thanks in advance, Marko Vuksanovic. public class PhotosCollection { public static DataSet ds; private DataTable photoDataTable= new DataTable(); private ObservableCollection<Photo> photos = new ObservableCollection<Photo>(); public ObservableCollection<Photo> Photos { get { return this.photos; } } public void GetData() { photoDataTable=ds.Tables["photo"]; photos.Clear(); for (int i = 0; i < photoDataTable.Rows.Count; i++) { photos.Add(new Photo((int)photoDataTable.Rows[i][0], (string)photoDataTable.Rows[i][1], (long)photoDataTable.Rows[i][2], (int)photoDataTable.Rows[i][3], (string)photoDataTable.Rows[i][4], (int)photoDataTable.Rows[i][5], (int)photoDataTable.Rows[i][6], (int)photoDataTable.Rows[i][7])); } } } public class Photo { private int id; private string owner; private long secret; private int server; private string title; private int ispublic; private int isfriend; private int isfamily; private StreamReader photoURL; public Photo(int id, string owner, long secret, int server, string title, int ispublic, int isfriend, int isfamily) { this.id = id; this.owner = owner; this.secret = secret; this.server=server; this.title = title; this.ispublic = ispublic; this.isfriend = isfriend; this.isfamily = isfamily; photoURL= new StreamReader("http://static.flickr.com/"+this.server+"/"+this.id+"_"+this..secret+"_t.jpg"); this.thumbNailPhoto = ImageFromString(photoURL); } public ImageSource ThumbNailPhoto { get { return this.thumbNailPhoto; } ImageSource thumbNailPhoto; public ImageSource ImageFromString(StreamReader url) { BitmapImage image = null; if (url != null) { image = new BitmapImage(); image.BeginInit(); image.StreamSource=new Stream(url); image.EndInit(); } return image; } } |
|||||||||||||||||||||||