MICROSOFT GULF COMMUNITY BLOG

The communication portal to the Gulf technical audience

Step-by-step tutorial to merge text on image (customize live tiles) and save it into the media library - Windows Phone 8 - Visual Studio 2012 using C#

Step-by-step tutorial to merge text on image (customize live tiles) and save it into the media library - Windows Phone 8 - Visual Studio 2012 using C#

Rate This
  • Comments 2

Would you like to update your live tiles to a customized one? Here is the step by step tutorial on how to merge text on an image.

To merge text and image into a single image, we have to convert the image to a writable bitmap, render the text over the image and position it, and then save the image.

Let’s say I have an image “myImage”

morning

1) Create a textblock and name it “textblock1”

2) Assign some text to the textblock

     textblock1.Text = “Good morning”;

3) Convert the image to a writeable bitmap

          WriteableBitmap wb = new WriteableBitmap((BitmapSource)myImage.Source);

4) Position the textblock over the writeable bitmap

          wb.Render(textblock1, new TranslateTransform() { X = 25, Y = 191 });
          wb.Invalidate();

5) Save the image as jpeg to the media library

          using (MemoryStream stream = new MemoryStream())
          {
              wb.SaveJpeg(stream, wb.PixelWidth, wb.PixelHeight, 0, 100);
              stream.Seek(0, SeekOrigin.Begin);
              using (MediaLibrary mediaLibrary = new MediaLibrary())
                  mediaLibrary.SavePicture("Picture.jpg", stream);
          }
          MessageBox.Show("Picture Saved...");

gm

  • media library is not available in my visual studio express 2012.how can i save the image?

  • Hi Shamlia:

    Which namespace should one add for medialibrary, I'm using VS 2012 ultimate ? Furthermore, what sort of object is this "myImage" ? Considering I'm using System.Windows.Media.Imaging.BitmapImage object for myImage, then is this typecasting to WriteableBitmap OK ?

                   System.Windows.Media.Imaging.BitmapImage bmpImage = new   System.Windows.Media.Imaging.BitmapImage();

                   bmpImage.SetSource(e.ChosenPhoto);

                   WriteableBitmap wb = new WriteableBitmap((BitmapSource)bmpImage);

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 3 and 8 and type the answer here:
  • Post