Silverlight for Windows Phone Programming Tip #1

I’m spending the bulk of my time these days writing applications for Windows phones using Silverlight for Windows Phone (and having a blast doing it, I might add). As I write, I think of lots of little tips that can save time, reduce aggravation, and help all of us build better applications. So I thought I’d begin a series of tips that I can add to over time. This is the first in that series.

The Silverlight for Windows Phone documentation contains a helpful article demonstrating how to encode a WriteableBitmap as a JPEG and use the XNA framework’s MediaLibrary class to save it in the phone’s pictures library. The code works, but it’s way more work than you have to do.

Rather than create a temporary file in isolated storage, write the JPEG into the temporary file, transfer the JPEG from isolated storage into the pictures library, and then delete the file per the example in the documentation, you can accomplish the same thing with four lines of code:

 

using (MemoryStream stream = new MemoryStream(bitmap.PixelWidth * bitmap.PixelHeight * 4))

{

    Extensions.SaveJpeg(bitmap, stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);

    MediaLibrary library = new MediaLibrary();

    library.SavePicture(“SavedPicture.jpg”, stream.ToArray());

}

 

In this example, bitmap is a variable containing a reference to the WriteableBitmap you wish to encode and save. The MediaLibrary class is found in the Microsoft.Xna.Framework assembly, so you’ll need to add a reference to that assembly to your project in order to use it.

2075

The Right Solution for Your Needs.

We deliver a hybrid spectrum of Microsoft Cloud Platform and Azure solutions to government agencies and application developers who demand a modern, open and flexible cloud service platform. We offer trusted, transparent, and secure Infrastructure as a Service (IaaS) and Platform as a Service (PaaS) solutions for production business applications, Business Intelligence (BI), continuous data protection, application availability, test/development, and Software as a Service (SaaS)

Architected to meet your needs.

Deployed flawlessly.

Operated reliably 24x7x365.

Assess:

Rely on our team to map your existing environment to a corresponding 
Azure cloud.

Migrate:

Easily move from your existing environment to a public or private Microsoft cloud.

Re-platform:

Understand how to transform your applications to better take advantage 
of cloud capabilities.

Operate:

Our team actively manages all maintenance & optimization to keep your environment running at its best.

Why Microsoft Cloud Platform and Azure?

Microsoft has made major strides in the public cloud space over the past few years. They are gaining market momentum with companies and also the analysts community who recognize the more than USD15B investment made. At this point Azure has more data centers than AWS and Google Cloud combined. It spans an unparalleled global reach with 36 regions available and more being added. Azure offers companies wanting to put workload in the a public cloud with a secure, scalable and competitive option.

2204

Azure Certified for Hybrid Cloud.

Atmosera has developed core competencies and intellectual property to take full advantage of all Azure has to offer. All Atmosera Azure services receive the “Azure Certified for Hybrid Cloud” designation which confirms it passed Microsoft’s rigorous validation process under the Cloud OS Network (COSN) program. Customers benefit from knowing that their solution was carefully planned and executed using best practices and proven methods.

Stay Informed

Sign up for the latest blogs, events, and insights.

We deliver solutions that accelerate the value of Azure.
Ready to experience the full power of Microsoft Azure?

Atmosera is thrilled to announce that we have been named GitHub AI Partner of the Year.

X