×

Discussion Board

Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    419

    Re: Export a screenshot of a component that's not visible

    In first step, You could try to add your custom component to the visualtree (it normally can be hidden) and try to make the rendering. Normally it should works.

    You say you use an Image, maybe the problem is the picture decoding which is decoded in background? How do you give the picture to your control?
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  2. #17
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: Export a screenshot of a component that's not visible

    Code:
    <telerikSlideView:PanAndZoomImage Source="{Binding ImageUri}"
                                                  Stretch="Fill"
                                                  x:Name="BackgroundImage"
                                                  x:FieldModifier="public"/>
    This is how I load the image.

    I can try adding the element to the visualtree, but even if this works, how can I make it work in background agent if there's no visual tree?

    I'm afraid that there's no way out of there :\

  3. #18
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    477

    Re: Export a screenshot of a component that's not visible

    Why don't you just use Image?

    telerikSlideView:PanAndZoomImage is overkill as you're only generating an image that the user cannot even interact with at the time.

  4. #19
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    419

    Re: Export a screenshot of a component that's not visible

    You could try Dispatcher.BeginInvoke.
    As Image loading is asynchrone (maybe binding too) you make rendering after first events are executed.

    Code:
    var bitmap = new WriteableBitmap(400, 800);
    var size = new Size(400, 800);
    var rect = new Rect(0, 0, 400, 800);                                   
    var grid = new Grid {Background = new SolidColorBrush(Colors.Red)};
    var lockscreen = new LockscreenControl(model);                                        
    grid.Children.Add(lockscreen);
    grid.Measure(size);
    grid.Arrange(rect);
    grid.UpdateLayout();
    Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        bitmap.Render(grid, new TranslateTransform {X = 0, Y = 0});
        bitmap.Invalidate();
        using (var mediaGallery = new MediaLibrary())
        using (var stream = new MemoryStream())
        {
            bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight,0, 100);
            stream.Seek(0, SeekOrigin.Begin);
            mediaGallery.SavePicture(FILE_NAME, stream);
         }
         MessageBox.Show("Picture saved");
    });
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  5. #20
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: Export a screenshot of a component that's not visible

    @theothernt: Nice point, I've changed it with a simple Image control.

    @yan_: I've just tried your code, but it just renders the Grid.

    I don't know what's your role here, if you're like moderators and experts or you can actually report something to Nokia/Microsoft, but I think that this behavior of the WriteableBitmap doesn't fit a system in which lockscreen customization is one of the key features so, if you can do it, please let someone know that a better WriteableBitmap would be really appreciated.

    I'd use http://wpdev.uservoice.com but, for some reason, it doesn't post my idea (the spinner keeps on running forever)

  6. #21
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    427

    Re: Export a screenshot of a component that's not visible

    You can read about the Champion Program here: https://developer.nokia.com/Community/Champions/

  7. #22
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    419

    Re: Export a screenshot of a component that's not visible

    Quote Originally Posted by StepTNT View Post
    @yan_: I've just tried your code, but it just renders the Grid.
    It's a beginning
    Maybe you need wait more time before rendering. You could try a DispatcherTimer and wait 1 second before rendering?
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  8. #23
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    477

    Re: Export a screenshot of a component that's not visible

    Quote Originally Posted by StepTNT View Post
    if you're like moderators and experts or you can actually report something to Nokia/Microsoft, but I think that this behavior of the WriteableBitmap doesn't fit a system in which lockscreen customization is one of the key features so, if you can do it, please let someone know that a better WriteableBitmap would be really appreciated.
    What you're trying to do does work (ie. generate a nice custom image to use on the lockscreen) and I don't think it's an issue with WritableBitmap, generating images within a Background Agent is tricky due to the memory limitations.

    Myself and the other devs are here to help

    Have you ever generated live tiles in your app before?

  9. #24
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    427

    Re: Export a screenshot of a component that's not visible

    I built a small sample application that we might be able to have a common testing ground. Instead of saving the WritableBitmap to the Media Library I'm displaying it inside an Image control (out of laziness).

    What I'm doing currently is load a background image (using WritableBitmapEx), setting that as the background of the Grid (using an ImageBrush) and rendering some text above it. I don't know if that's a particularly resource efficient way to do it (WritableBitmapEx is a great library but not really memory friendly quite often).

    You can find the project here: http://sdrv.ms/1d5kCeT

    PS: I have played some more with it and been able to create a call that uses a UserControl as the render source. However I have not been able to get regular BitmapImages to work and neither did setting the Image Source in XAML. However loading the Image in the WritableBitmap in Code Behind and rendering that works just fine.

    That's what my code does here: http://sdrv.ms/19x5x3m

    Looking around this seems to be a general issue with the WritableBitmap Rendering in Silverlight (which the WP UI is based upon). The reason seems to be that the images are loaded asynchronously after they are first needed. Due to that they are not loaded when Render is called. Perhaps someone has a better idea on how to achieve the loading (perhaps using the imaging SDK).
    Last edited by SB Dev; 2013-12-09 at 21:15.

  10. #25
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: Export a screenshot of a component that's not visible

    Let me clarify something before we're going on.

    I'm building an app to customize the lockscreen, and that's why I need to export the image.
    The app is really complex. I think that mine is a quite new concept to WP's world, and that's why I'm not providing any code.

    At the moment, the export that I'm trying is done in the main app, I'm not using any background thread so it doesn't fail because of any memory error.

    The main problem is not that it doesn't load the image, the problem is that everything is based on binding and it seems that there's no way to make it work.

    I've just tried using the DispatcherTimer with no success, so it seems that the binding doesn't happen at all! (I've set the interval to 5 seconds instead of the suggested value)
    I've also tried SB Dev's project, and I've edited a little bit to provide a non-working version to be studied, so here's what I've changed:

    Code:
    public partial class MyUserControl : UserControl
        {
            // Added some properties to be bound
            public string TestText { get; set; }
            public ObservableCollection<string> Texts { get; set; } // The content of this collection is displayed if I load the control but it's not rendered, just like happens in my app
            public Thickness RandomPosition
            {
                get
                {
                    return new Thickness(new Random().Next(200));
                }
            }
    
            public MyUserControl()
            {
                InitializeComponent();            
                TestText = "BINDING";
                Texts = new ObservableCollection<string>
                {
                    "test1", "test2", "test3"
                };
                DataContext = this;
                var bitmap = new WriteableBitmap(400, 800);
                var resource = App.GetResourceStream(new Uri("background.jpg", UriKind.Relative));
                bitmap.LoadJpeg(resource.Stream);
                imgBg.Source = bitmap;
            }
        }
    Code:
    <UserControl x:Class="RenderTestApp.MyUserControl"
                 x:Name="USerControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        d:DesignHeight="800" d:DesignWidth="480">
    
        <Grid x:Name="LayoutRoot">
            <Image x:Name="imgBg"/>
            <TextBlock Text="{Binding TestText}" Foreground="Green" FontSize="120"/>
            <ItemsControl ItemsSource="{Binding Texts}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}"
                                   Margin="{Binding RandomPosition, ElementName=USerControl}"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
    </UserControl>
    What happens now is that loading MyUserControl into the XAML makes everything display fine, but calling the Render method shows just the "BINDING" text and none of the elements contained in the ItemsControl

    This is crucial, as my LockscreenControl is basically an Image overlayed by an ItemsControl.

    Now, since I fear that this is going nowhere and I don't want to waste your time, I'm making a new project to work with, so that you can see what I'm seeing.
    This new project is made by removing stuff from the current app, so you'll have my real code.

    I'll update this post with the link to download the solution.

    A BIG thanks to everyone who's trying to help me, it's really nice to see people that enjoy wasting time helping a stranger

    EDIT:

    Here's the project.
    http://sdrv.ms/1kwhpI5

    EDIT 2:

    Here's a BIG update to the whole thread.
    I've been able to do a render of the control by rebuilding the UI using code but it's still not perfect (you can see some differences between the render and the expected result, and it's basically related to the control's position)

    I'm adding a new link to a smaller project because I can't find why the position is wrong and I need your help again.

    (I don't remember how to get the short URL from the SkyDrive Desktop App or the Mobile One :\)
    https://skydrive.live.com/?cid=9a21e...B1BF2230!73089
    Last edited by StepTNT; 2013-12-22 at 12:33. Reason: Updated the Project

Similar Threads

  1. Get a screenshot
    By er_benji in forum Symbian Media (Closed)
    Replies: 14
    Last Post: 2012-02-22, 12:39
  2. Take a screenshot and save it .
    By droopyar in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2011-11-27, 09:28
  3. Screenshot
    By mohitrb1 in forum Mobile Java General
    Replies: 22
    Last Post: 2010-03-26, 14:03
  4. screenshot not possible
    By _Askin_ in forum Mobile Web Server
    Replies: 4
    Last Post: 2008-05-30, 07:27
  5. Carbide developer wont import EXPORT commands from EXPORT.MAKE
    By jimgilmour1 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 3
    Last Post: 2006-10-26, 06:27

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •