0

I have an image app in wp7.

class Images
{
   public string Title {get;set;}
   public string Path {get;set;}
}

on page level, i bind title and path(relative to my app) it to a list.

What i need is, when user click on list item the respective image open in picture gallery of windows phone 7.

Saboor Awan
  • 1,567
  • 4
  • 24
  • 37

1 Answers1

0

You should clarify your question, but I suppose Path is the location of your image in isolated storage. Providing that Image is the name of your Image in xaml

img.Source = GetImage(LoadIfExists(image.Path));

LoadIfExists returns the binary data for a file in Isolated Storage, and GetImage returns it as a WriteableBitmap :

    public static WriteableBitmap GetImage(byte[] buffer)
    {
        int width = buffer[0] * 256 + buffer[1];
        int height = buffer[2] * 256 + buffer[3];

        long matrixSize = width * height;

        WriteableBitmap retVal = new WriteableBitmap(width, height);

        int bufferPos = 4;

        for (int matrixPos = 0; matrixPos < matrixSize; matrixPos++)
        {
            int pixel = buffer[bufferPos++];
            pixel = pixel << 8 | buffer[bufferPos++];
            pixel = pixel << 8 | buffer[bufferPos++];
            pixel = pixel << 8 | buffer[bufferPos++];
            retVal.Pixels[matrixPos] = pixel;
        }

        return retVal;
    }

    public static byte[] LoadIfExists(string fileName)
    {
        byte[] retVal;

        using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (iso.FileExists(fileName))
            {
                using (IsolatedStorageFileStream stream = iso.OpenFile(fileName, FileMode.Open))
                {
                    retVal = new byte[stream.Length];
                    stream.Read(retVal, 0, retVal.Length);
                }
            }
            else
            {
                retVal = new byte[0];
            }
        }
        return retVal;
    }

If you want to write the image into the Picture Library, it's basically the same process, ending by calling SavePictureToCameraRoll() of MediaLibrary as explained on this MSDN Article

Thomas Joulin
  • 6,590
  • 9
  • 53
  • 88
  • i have images in folder of my application, say images\image1.png, images\image2.png ,etc. i want these images to open in picture gallery so that user can play with the image as in picture gallery – Saboor Awan Nov 30 '11 at 08:42
  • I've updated my answer. The "folder" in you application is called Isolated Storage, so my original answer fits to load this image. The Picture Gallery is called Picture Library by Microsoft, my update links to an article from MSDN giving all you need. You can't however launch the Pictures app from within your App. – Thomas Joulin Nov 30 '11 at 10:18