Screen Capture on Windows Phone 7#

In some instances when working on projects we would require to take a screen capture of the current screen the user is working on.  I regularly did this on .NET Compact Framework 3.5 (pre Windows Phone 7) and is a little bit of mess because of all the PInvokes involved. 

I decided to create a quick sample app that captures the screen on both platforms to compare the code.  The sample app basically just places the captured screen inside a pictureBox control (NETCF 3.5) or Image control (Silverlight for WP7).  The outer PictureBox/Image control just displays some standard images that come with Windows 7.

Compact Framework 3.5   Silverlight (Windows Phone 7)
image   image

Here is a comparison of capture an image of the current screen on Windows Phone 7 using Silverlight and .NET Compact Framework

.NET Compact Framework

private Bitmap CaptureScreen()
{
    Bitmap b = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    using (Graphics g = Graphics.FromImage(b))
    {
        IntPtr hdcSrc = IntPtr.Zero;
        IntPtr hdcDest = g.GetHdc();
        try 
        {
            //get the entire window by passing in IntPtr.Zero
            hdcSrc = GetWindowDC(IntPtr.Zero);
            //blit to the graphics object g
            BitBlt(hdcDest, 0, 0, b.Width, b.Height, 
                hdcSrc, 0, 0, SRCCOPY); 
        }
        finally
        {
            //Release any native src hdcs
            if (hdcSrc != IntPtr.Zero)
            {
                ReleaseDC(hdcSrc);
                DeleteDC(hdcSrc);
            }

            //Release the graphics hdc
            g.ReleaseHdc(hdcDest);
        }
    }

    return b;
}

[DllImportAttribute("coredll.dll")]
public static extern IntPtr GetWindowDC(IntPtr hWnd);

[DllImport("coredll")]
public static extern int DeleteDC(IntPtr hdc);

[DllImportAttribute("coredll.dll")]
internal static extern IntPtr ReleaseDC(IntPtr hdc);

public const int SRCCOPY = 0x00CC0020;

[DllImport("coredll.dll")]
public static extern bool BitBlt(IntPtr hdcDest, 
    int nXDest, int nYDest, int nWidth, 
    int nHeight, IntPtr hdcSrc, int nXSrc, 
    int nYSrc, uint dwROP);

Windows Phone 7 using Silverlight

private void btnCaptureScreen_Click(object sender, RoutedEventArgs e)
{
    //Capture the screen and set it to the internal picture box
    WriteableBitmap bmp = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
    bmp.Render(this, null);
    bmp.Invalidate();
    this.image1.Source = bmp;
    
    //Set a new background
    ImageBrush brush = new ImageBrush();
    brush.ImageSource = new BitmapImage(new Uri(NextImage,UriKind.Relative));
    ContentGrid.Background = brush;
    
}

Essentially the apps do the same thing but it’s a lot easier to do it on one than the other.  Here are some quick highlights on the differences.

  1. Silverlight for Windows Phone 7 has 7 lines of code while the .NET Compact Framework version has 28 lines of code
  2. With Silverlight for Windows Phone 7 you don’t have to deal with PInvokes anymore.
  3. Windows Phone 7 codebase is a lot smaller and more maintainable.
  4. With silverlight for Windows Phone 7, controls automatically support transparencies which was a challenge on NETCF 3.5 (notice the white box on NETCF 3.5 screen, that’s a PictureBox control
  5. Currently on Windows Phone 7 there is no way to get the images from your device in the form of a file unless you upload to a web service or something similar

Give it a try for yourself and download the sample code here.


Monday, April 19, 2010 1:42:59 PM (Eastern Daylight Time, UTC-04:00) #    Comments [2]  |  Trackback

 

EnergizeIT: From the Client to the Cloud – The Mobile App#

I few months ago RedBit was asked by Microsoft to help them create a Windows Phone 6.5 demo application for EnergizeIT: From the Client to the Cloud tour across Canada. 

The purpose of the mobile software was to allow a fictitious insurance company to AppLogo_Splash_VGA_thumb[7] collect car accident information from a consumer. The consumer would be able to fill in basic information about the accident, take pictures of the incident, get the GPS location including address of the accident and submit this to a backend system where the data can be collected and acted upon.  The goal was to show EnergizeIT attendees how to leverage the Microsoft based platform and tools such as Silverlight, .NET 4.0, Azure and Visual Studio 2010.  The mobile software used .NET Compact Framework 3.5 but I’ll have a future post on porting it to Windows Phone 7.

RedBit’s role was to get the data from the Windows Phone to the backend database.  Our goal was also to make the mobile app look a little nicer than traditional Windows Mobil apps. What we created is a mobile client to have the consumer enter accident information and also created a WCF service to allow consumers to submit the data for the insurance company to act on. 

image image image

For location support we created a WCF service to reverse geocode a location to provide a readable address and an image of the location via Bing Maps API.

image image

The user would also be able to see their insurance card and the autos that are insured cars under their policy.

image image

We also included a feature called On The Road that allowed you to search for various services around you. 

imageBy the way, you can download Find My Bru from Windows Phone Marketplace now.

Overall, I think we were able to deliver a pretty good looking functional app on Windows Phone 6.5 (with a lot of effort for the UI).  Thanks to Christian Beauclair and the rest of the Canadian DPE team for giving us the opportunity to build this app for Windows Phone. 

Unfortunately, I won’t be publishing the source to this app but will be following up on blog posts showing some code snippets that I think will be useful to the developer community. 

I’ll also be following up in another blog post on porting this mobile application to Windows Phone 7 and what code we were able to re-use and most importantly, how easy it is to make a good looking app on Windows Phone 7.

If you want more info on the app please feel free to contact us at info[@]redbitdev[dot]com


Tuesday, April 06, 2010 3:16:49 PM (Eastern Daylight Time, UTC-04:00) #    Comments [1]  |  Trackback

 

Win A Car with MuchMusic and Windows Phone#

I recently wrote about the Much On Demand (or MOD for short) application for Windows phone

If you are a resident of Canada, you have a chance to win some great prizes from a 2009 Mitsubishi Lancer to  Samsung Omnia II Windows Phones, Samsung Cameras, camcorders and netbooks!! 

How do you win?  Watch Holiday Wraps programs on MuchMusic on the local cable or satellite channel in your area from Sunday, December 13, 2009 to Sunday, January 03, 2010 and lock for this contest clue.

27_clue

Enter your clues and you could win!  While your at it, don’t forget to download  MOD for Windows Phone!

Car


Friday, December 18, 2009 10:02:07 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  |  Trackback

 

Much On Demand for Windows Phone#

RedBit just completed a project with MuchMTV Networks to bring their Much On Demand brand for MuchMusic to Windows Phone

What does the MOD for Windows Phone app do?  Allows you to see what’s coming up for the week, upcoming guests, request tickets for the live MOD show, view pictures of past guests and vote for the Top Daily 5.  There is even integration with Twitter and Facebook.

Download now MuchOnDemand for your Windows Phone from Windows Marketplace for Mobile directly from your Windows Phone.  If you don’t have Windows Marketplace for Mobile browse to mp.marketplace.com from your phone to get it and get MuchOnDemand for your Windows Phone.

MuchOnDemand for Windows Phone


Friday, December 18, 2009 10:40:36 AM (Eastern Standard Time, UTC-05:00) #    Comments [0]  |  Trackback

 

Windows Mobile Developer Camp – Toronto – The Details#

clip_image002[6]

I recently wrote about the Toronto version of winmodevcamp and we finally have all details.  Be sure to join us as all Canadian carriers will be present including the newest company to the wireless sector WIND (Globalive Communications).  Be sure to register for winmodevcamp and join us!

WinMoDevCamp will be coming to Toronto on November 11th 2009. WinMoDevCamp is a series of not-for-profit gatherings to develop applications for the newly released Microsoft Windows Phone 6.5 O/S. This “Camp” has been held in other predominant cities such as Seattle and San Francisco, and will also be taking place in New York, London, Tokyo and many other cities around the world. Register Here.

Attendees will include mobile developers, web developers, .Net Developers, UI designers, testers, device manufactures and Canadian Carriers, all working together. Development projects will include both solo and team efforts. While some attendees will wish to work solo during the event, we encourage attendees to team up, based on expertise, to work in ad-hoc project development teams. All attendees should be prepared to work on a development project during the event.

Attendees will be able to:

  • Create new applications for the Windows Mobile Platform.
  • Meet and work side-by-side with team members from the Microsoft Mobile Developer Experience team.
  • Gain assistance in migrating existing mobile applications from the iPhone, Blackberry and Palm Pre to the Windows Mobile Platform.
  • Create applications to support Windows Enterprise Applications.
  • Interact with Canadian Wireless Carrier representatives
    (Bell, Telus, Rogers & WIND)

Many thanks to the Microsoft Mobile Developer Experience team for their support in making these events happen! I want to specifically thank Loke Uei, Senior Technical Project Manager on the Microsoft Mobile Developer Experience team for not hesitating in giving his full support to the community.


Thursday, October 29, 2009 7:05:05 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

All content © 2010, Mark Arteaga
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts