Ask a questionAsk a question
 

AnswerSizing and GetCapabilitiesForDevices

  • Saturday, July 25, 2009 5:47 AMRobert.Klenka Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Ok i have a question, i want to use my SideShow gadget across many devices at the same time.

    The problem i am having is that each one is a different screen size and resolution, i read that you use GetCapabilitiesForDevices to find the sizes:
    .GetScreenHeight() .GetScreenWidth() but GetCapabilitiesForDevices gets them as a Array depending on what devices are plugged in.

    Is there away to connect the Array numbers, with the devices to then change the size depending on the devices it sends it to?

    Like:
    Send Device A the Image this Size
    Send Device B the Image this Size
    Send Device C the Image this Size

    I know i can just have one device selected and use its size and i also know that i can sort through them all and get the smallest size so that they fit all of them but some sizes are drastically different between the devices.

    Any ideas?

Answers

  • Saturday, July 25, 2009 10:27 AMJames Woodall Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi Robert,

    Absolutely this is possible although the problem is tackled from a slightly different angle.

    Essentially, the theory involves creating a piece of content that is dynamic across devices.  Then, each time the content is requested by the SideShow runtime, a different Image is sent for each device.

    The ISideShowContent COM reference explains a little about how this works for C++ users (the C# documentation is not as fleshed out): http://msdn.microsoft.com/en-us/library/cc982281(VS.85).aspx.

    Therefore, you must create your own "ResizeImageContent" class.  The Microsoft.SideShow.Content class can be inherited.  By setting "differentiateContent" to true in the constructor, you are indicating that each device renders a slightly different version of the image.

    Then, when OnGetContent is called (a method you must override in your own Content class implementation) the capabilities for the device in question are sent.  Based on these capabilities you can resize your image accordingly.  Once you know the byte structure of the content to send, simply return it in the OnGetContent method.

    Warning: not all devices support capabilities.  Calling GetScreenHeight / GetScreenWidth may throw exception if the device doesn't report these.  Therefore, try/catch the block and return a default image if this fails (or nothing at all, upto you).

    By using this approach you need not take note of all devices and instead only respond to devices as and when they request the content.

    With images, you will need to ensure that the byte[] you return is in an appropriate compression format for that device.  For example, if possible use PNGs but some of the .NET MF renderers (the simulator for example) don't support PNGs and should be GIF or JPEG.

    Once you have created your content class, you can then add it as you would normally using the AddContent method of your SideShowGadget object.

    Hope this helps (code enclosed below),

    class ResizeImageContent : Content
    {
        public ResizeImageContent(int contentId, Bitmap bmp)
            : base(contentId, true) /* the "true" parameter is the DifferentiateContent */
        {
            ImageToResize = bmp;
        }
    
        public Bitmap ImageToResize { get; set; }
    
        protected override byte[] OnGetContent(DeviceCapabilities caps)
        {
            //Using the caps parameter, resize and return the image
    
            //Be aware, not all devices must support capabilities 
            //so return a default image or nothing if cannot get caps
            //otherwise your gadget will crash
        }
    }
    

    -james (Ikanos Consulting)

All Replies

  • Saturday, July 25, 2009 10:27 AMJames Woodall Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi Robert,

    Absolutely this is possible although the problem is tackled from a slightly different angle.

    Essentially, the theory involves creating a piece of content that is dynamic across devices.  Then, each time the content is requested by the SideShow runtime, a different Image is sent for each device.

    The ISideShowContent COM reference explains a little about how this works for C++ users (the C# documentation is not as fleshed out): http://msdn.microsoft.com/en-us/library/cc982281(VS.85).aspx.

    Therefore, you must create your own "ResizeImageContent" class.  The Microsoft.SideShow.Content class can be inherited.  By setting "differentiateContent" to true in the constructor, you are indicating that each device renders a slightly different version of the image.

    Then, when OnGetContent is called (a method you must override in your own Content class implementation) the capabilities for the device in question are sent.  Based on these capabilities you can resize your image accordingly.  Once you know the byte structure of the content to send, simply return it in the OnGetContent method.

    Warning: not all devices support capabilities.  Calling GetScreenHeight / GetScreenWidth may throw exception if the device doesn't report these.  Therefore, try/catch the block and return a default image if this fails (or nothing at all, upto you).

    By using this approach you need not take note of all devices and instead only respond to devices as and when they request the content.

    With images, you will need to ensure that the byte[] you return is in an appropriate compression format for that device.  For example, if possible use PNGs but some of the .NET MF renderers (the simulator for example) don't support PNGs and should be GIF or JPEG.

    Once you have created your content class, you can then add it as you would normally using the AddContent method of your SideShowGadget object.

    Hope this helps (code enclosed below),

    class ResizeImageContent : Content
    {
        public ResizeImageContent(int contentId, Bitmap bmp)
            : base(contentId, true) /* the "true" parameter is the DifferentiateContent */
        {
            ImageToResize = bmp;
        }
    
        public Bitmap ImageToResize { get; set; }
    
        protected override byte[] OnGetContent(DeviceCapabilities caps)
        {
            //Using the caps parameter, resize and return the image
    
            //Be aware, not all devices must support capabilities 
            //so return a default image or nothing if cannot get caps
            //otherwise your gadget will crash
        }
    }
    

    -james (Ikanos Consulting)
  • Saturday, July 25, 2009 3:51 PMRobert.Klenka Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Well the way i had it now was that it would get the smallest size out of the devices (one didnt even have the capabilities) and then resize the image to be sent which was usually 170px, i even sent one out to the SideBar device i made for it that was 130px but when viewed on a vga screen (480px) it was just way to small. But this way sounds great.

    Thanks for the quick reply, maybe ill have something worked out by the end of the day.
  • Saturday, July 25, 2009 5:59 PMRobert.Klenka Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Oh man it works brilliantly thanks!