CoverFlow not work with MemoryStream why?

16 posts, 0 answers
  1. xax_007
    xax_007 avatar
    13 posts
    Member since:
    Jul 2009

    Posted 16 Dec 2009 Link to this post

    Hello,

    I´m testing CoverFlow but i transform the Bytes[] from database, to image with MemoryStream, BitmapImage etc...

    But the images show a little seconds but after disappers, this is a CoverFlow problem or is my code?

    //GLOBAL VARIABLES  
            List<Byte[]> lB = new List<byte[]>();  
     
            List<Byte[]> lbuffer = new List<byte[]>();  
     
            ObservableCollection<Image> lI = new ObservableCollection<Image>();  
     
            List<MemoryStream> lMS = new List<MemoryStream>();  
     
            List<BitmapImage> lBM = new List<BitmapImage>();  
     
            Object o = new object();  
     
    void client_GetImagesSFCompleted(object sender, ImagesLibraryView.GetImages.GetImagesSFCompletedEventArgs e)  
            {  
                o = e.Result.Clone();  
     
                foreach (Object img in (Object[])o)  
                {  
                    lB.Add((Byte[])img);  
                }  
     
                foreach (Byte[] bA in lB)  
                {  
                    MemoryStream mS = new MemoryStream(bA);  
     
                    mS.Write(bA, 0, bA.Length);  
     
                    lMS.Add(mS);  
                }  
     
                foreach (MemoryStream mS in lMS)  
                {  
                    BitmapImage imgBM = new BitmapImage();  
     
                    imgBM.SetSource(mS);  
     
                    lBM.Add(imgBM);  
                }  
     
                foreach (BitmapImage bmI in lBM)  
                {  
                    Image I = new Image();  
                    I.Width = 200;  
                    I.Height = 200;  
                    I.Stretch = Stretch.None;  
                    I.Source = bmI;  
                      
                    lI.Add(I);  
                }  
     
                CoverFlow.ItemsSource = lI;  
     
            } 

    I get an array of images in e.Result, this is a reply of webservice Async and my images are in jpg, all is correctly.
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 17 Dec 2009 Link to this post

    Hello,

    If RadCoverFlow is populated with Image elements, in order to provide loading animation, it attaches event handler on the ImageLoaded event of each image. I suppose that when the ImageSource is loaded from a MemoryStream, the ImageLoaded event is not fired, hence RadCoverFlow does not display the image. I would recommend trying to wrap each image in a Border - this will prevent RadCoverFlow from attaching handlers on those events and will display the images without loading animation. Other option would be to add the ImageSource objects to the ItemsSource collection of RadCoverFlow and provide a ItemTemplate, containing the data-bound image.

    All the best,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. phlogiston
    phlogiston avatar
    6 posts
    Member since:
    Dec 2009

    Posted 12 Jan 2010 Link to this post

    Hi,

    I suppose i have an identical problem; my Images come as a list of Byte[] through WCF-Service.
    I set them as source for MemoryStreams and those again as source for BitmapImages, who themselves become sources for Images,
    obviously just like xax_007 did.
    The control loads, i can see the pictures for a second, then it continues to show only the loading animation.
    Besides you are right, Valeri, the ImageLoaded event never gets fired in this example.

    As you suggested, i tried to wrap a border around any image, which had no effect...

    Other option would be to add the ImageSource objects to the ItemsSource collection of RadCoverFlow and provide a ItemTemplate, containing the data-bound image.

    I am very new to this, could you please explain that a bit further?

    many thx in advance.
  5. phlogiston
    phlogiston avatar
    6 posts
    Member since:
    Dec 2009

    Posted 13 Jan 2010 Link to this post

    Thanks for any possible effort, but i was able to solve my problem.

    It is now indeed working with the DataContext property set.

    But anyway, i will stick to using the filepaths instead of Byte[]'s since loading would take too long.

    best wishes!
  6. xax_007
    xax_007 avatar
    13 posts
    Member since:
    Jul 2009

    Posted 13 Jan 2010 Link to this post

    this:

    Other option would be to add the ImageSource objects to the ItemsSource collection of RadCoverFlow and provide a ItemTemplate, containing the data-bound image.


    I think that can be a solution.

    But finally I create image to directory of my IIS, and in coverflow in my list of items source binding a string url for image...

    I don´t like this option because i have got to do a batch process for delete after the images..

    Thanks phlogiston.

    Salu2,
    Pablo
  7. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 13 Feb 2010 Link to this post

    Could you tell me how you got this to work?

    I want to do the exact same thing.

    Thanks a bunch,

    Helen
  8. xax_007
    xax_007 avatar
    13 posts
    Member since:
    Jul 2009

    Posted 14 Feb 2010 Link to this post

    Hello Helen,

    If use sitefinity for downloads images you have the url for the image in database, you can use this...

    Whit other source, you can use bitmap in silverlight, maybe can work..

    what scenay you have?

    Salu2,
    Pablo
  9. phlogiston
    phlogiston avatar
    6 posts
    Member since:
    Dec 2009

    Posted 15 Feb 2010 Link to this post

    Hello Helen,

    Here's an example of how i got CoverFlow to display my images:

    XAML:

    <telerikNavigation:RadCoverFlow x:Name="cfTest" ItemsSource="{Binding}" >
                <telerikNavigation:RadCoverFlow.ItemTemplate>
                    <DataTemplate>
                            <Image Source="{Binding FullPath}" Width="350" Height="350" Stretch="Uniform" />
                    </DataTemplate>
                </telerikNavigation:RadCoverFlow.ItemTemplate>
            </telerikNavigation:RadCoverFlow>

    and Code Behind:

    // This is the Callback of my GetImages WCF-Service call
    private void client_GetImagesCompleted(object sender, GetImagesCompletedEventArgs e)
    {
            cfTest.DataContext = e.Result;
    }

    In my case the Result here is a List of my custom Image-Class which consists only of the imagename and a property named FullPath, storing the absolute path to the image. In XAML you tell CoverFlow that the binding will follow at runtime, as well as which property of the binding will be the final imagesource.
    As i have tested before, this works as well with Byte[]'s if you convert them to "Image" as Pablo has done.

    Hope this is helpful; Best regards,

    Phlogiston
  10. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 15 Feb 2010 Link to this post

    Thank you, that makes perfect sense.

    In my case I too get a byte array for the images, and that was the part I wanted to make sure it could handle.

    Cheers,

    Helen
  11. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 12 May 2010 Link to this post

    <telerik:RadCoverFlow OffsetY="60" x:Name="CoverFlow1"  ItemsSource="{Binding}" > 
                <telerik:RadCoverFlow.ItemTemplate> 
                    <DataTemplate>                
                        <local:Cover Width="225" Height="225"></local:Cover> 
                    </DataTemplate> 
                </telerik:RadCoverFlow.ItemTemplate> 
            </telerik:RadCoverFlow> 
    and local:Cover is a usercontol with Image control
     <Image x:Name="CoverFlowControl" Source="{Binding ImageSources}"  Stretch="Fill" ImageFailed="Image_ImageFailed"  telerikNavigation:RadCoverFlow.EnableLoadNotification="True" /> 
    Calls The GetHistoryImage Method
    I am binding it though
     this.DataContext = LocalHistoryCollection.HistoryCollection ; 

    My class is
     public  class LocalHistoryCollection
        {

            public static List<LocalHistoryItem> HistoryCollection { get; set; }

        }

    public class LocalHistoryItem 
        { 
     
        
            public BitmapImage ImageSources { get; set; } 
            public string Title { get; set; } 
            public int ThumbImageWidth { get; set; } 
            public int ThumbImageHeight { get; set; } 
            public string Description { get; set; } 
            public LocalHistoryItem() 
            { 
                ImageSources = new BitmapImage(); 
            } 
     
        } 


     public  BitmapImage GetHistoryImage(string filename) 
            { 
                BitmapImage bi = new BitmapImage(); 
                try 
                { 
     
                    using (var store = IsolatedStorageFile.GetUserStoreForApplication()) 
                    { 
     
                        if (store.FileExists(string.Format("{0}.jpg", filename))) 
                        { 
                            using (isoStream = store.OpenFile(string.Format("{0}.jpg", filename), FileMode.Open)) 
                            { 
                                bi.SetSource(isoStream); 
                                return bi; 
     
                            } 
     
                        } 
                    } 
                } 
                catch (IsolatedStorageException ex) 
                { 
                    return bi; 
                } 
                return bi; 
                    
             } 
    The problem is, its always on loading animation. it does not load the images
  12. DragonBall
    DragonBall avatar
    53 posts
    Member since:
    Jul 2008

    Posted 12 May 2010 Link to this post

    problem solved i just remote the telerikNavigation:RadCoverFlow.EnableLoadNotification="True" from the Image control.
  13. Daniela
    Daniela avatar
    20 posts
    Member since:
    Jul 2011

    Posted 16 Sep 2011 Link to this post

    This solution did not work for me, can you please upload more from your code?
    some help would be really appreciated,

    kind regards,

  14. Daniela
    Daniela avatar
    20 posts
    Member since:
    Jul 2011

    Posted 16 Sep 2011 Link to this post

    @phlogiston

    This solution did not work for me, can you please upload more from your code?
    some help would be really appreciated,

    kind regards,
  15. Daniela
    Daniela avatar
    20 posts
    Member since:
    Jul 2011

    Posted 19 Sep 2011 Link to this post

    does any one from telerik know the solution? any help would be very appreciated.
  16. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 20 Sep 2011 Link to this post

    Hello Daniela,

    We don't know what problem you are experiencing and without a project that demonstrates it, we are shooting in the dark. What I could suggest you is to try to load the images without a CoverFlow control - this could help you to isolate the problem you are experiencing. This post could be helpful.

    Kind regards,
    Miroslav Nedyalkov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  17. Daniela
    Daniela avatar
    20 posts
    Member since:
    Jul 2011

    Posted 28 Sep 2011 Link to this post

    Hi,

    thanks a lot for your reply, I could fix the error. I was not getting the correct image folder in the server. this is the code in case some one can use it:
    FullPath = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/imageFolderInTheServer/" + pictureName;

    Kind Regards,
Back to Top
DevCraft banner