Question about ObservableCollection and images

M

Marko Vuksanovic

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[0], (string)photoDataTable.Rows[1], (long)photoDataTable.Rows[2], (int)photoDataTable.Rows[3], (string)photoDataTable.Rows[4], (int)photoDataTable.Rows[5], (int)photoDataTable.Rows[6], (int)photoDataTable.Rows[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;
}
}
 
M

Marko Vuksanovic

Never mind... Figured it out....
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[0], (string)photoDataTable.Rows[1], (long)photoDataTable.Rows[2], (int)photoDataTable.Rows[3], (string)photoDataTable.Rows[4], (int)photoDataTable.Rows[5], (int)photoDataTable.Rows[6], (int)photoDataTable.Rows[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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top