开发者

Using Isolated Storage Images in the HubTiles

开发者 https://www.devze.com 2023-04-11 14:07 出处:网络
I let the users take images in my app and save the images in the Isolated Storage. I also use HubTiles in my app but the HubTiles use a Uri in their Source property but it can\'t recognize the isostor

I let the users take images in my app and save the images in the Isolated Storage. I also use HubTiles in my app but the HubTiles use a Uri in their Source property but it can't recognize the isostore:/..... Uris.开发者_JAVA技巧.

Any idea how can I fix this issue?


You are not the only one experiencing that the isostore:/ URIs are not functioning in every place an URI is expected. So it seems like you need to take the more traditional approach and load the image by hand:

    // define data array to hold image data to be read from isolated storage
    byte[] imageBytes;
    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        // open image file
        using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("MyPreviouslySavedImage.jpg", FileMode.Open, FileAccess.Read))
        {
            // allocate array large enough to hold the whole file
            imageBytes = new byte[fileStream.Length];

            // read all data to memory
            fileStream.Read(imageBytes, 0, imageBytes.Length);
            fileStream.Close();
        }
    }

    // create memory stream and bitmap
    MemoryStream memoryStream = new MemoryStream(imageBytes);
    BitmapImage bitmapImage = new BitmapImage();

    // memory stream is source of bitmap
    bitmapImage.SetSource(memoryStream);

    // finally assign image to hub tile
    hubTile1.Source = bitmapImage;

This works well (if there is an image in the isostore of course).

0

精彩评论

暂无评论...
验证码 换一张
取 消