Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Windows Phone Dev - สอนเขียน App บนโปรแกรม Windows Phone 7 , Windows Phone 8 > Windows Phone Image Source From Isolated Storage (Application Storage)



Clound SSD Virtual Server

Windows Phone Image Source From Isolated Storage (Application Storage)

Windows Phone Image Source From Isolated Storage (Application Storage) สำหรับ Controls Image สามารถเรียก Source ได้หลากหลาย เช่นจาก Local หรือจาก URL รวทั้งการอ่าน Source ที่อยู่ใน Isolated Storage ของ Application และตัวอย่างนี้เรามาดูการอ่าน Source จาก Isolated Storage แบบง่าย ๆ โดยในขั้นตอนการอ่านนั้นเราจะไม่สามารถอ่าน Path ได้โดยตรง แต่จะต้องใช้การอ่านข้อมูลภาพที่ได้ให้อยู่ในรูปแบบของ Stream จากนั้นค่อยเอา Stream ที่ได้ กำหนด Source ให้กับ Image Control และแสดงผลในหน้า Page ของ Application

Windows Phone Image Source From  Isolated Storage

Windows Phone Image Source From Isolated Storage


Basic Windows Phone and Isolated Storage (Application Storage)

สำหรับพื้นฐาน Isolated Storage กับ Windows Phone ควรอ่าน 2 บทความนี้ เพื่อความเข้าใจ

Windows Phone Image Source From  Isolated Storage

รายการ Image ที่ถูกจัดเก็บไว้ใน Isolated Storage

Example ตัวอย่างการอ่าน Image Source จาก Isolated Storage และแสดงผลบน Controls ของ Image

MainPage.xaml

Windows Phone Image Source From  Isolated Storage

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Image Height="432" HorizontalAlignment="Left" Margin="41,58,0,0" Name="ImageFull" Stretch="Fill" VerticalAlignment="Top" Width="375" />
        </Grid>
    </Grid>









MainPage.xaml.vb (VB.NET)
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Windows.Media.Imaging

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    ' Constructor
    Public Sub New()
        InitializeComponent()

        AddHandler Loaded, AddressOf MainPage_Loaded
    End Sub

    Private Sub MainPage_Loaded(sender As Object, e As System.Windows.RoutedEventArgs)
        Dim strImageName As String = "img1.jpg"
        'Dim strImageName As String = "dir/img1.jpg" '*** for Sub Directory

        Dim image As New BitmapImage()
        Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
        Dim isoFilename As String = strImageName
        Dim stream As Stream = isoStore.OpenFile(isoFilename, System.IO.FileMode.Open)
        image.SetSource(stream)
        Me.ImageFull.Source = image
        stream.Close()

    End Sub

End Class

MainPage.xaml.cs (C#)
using System;
using System.Windows;
using System.Net;
using System.IO;
using System.Text;
using System.IO.IsolatedStorage;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace PhoneApp
{
    public partial class MainPage : PhoneApplicationPage
    {

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            Loaded += MainPage_Loaded;
        }

        private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            string strImageName = "img1.jpg";
            //Dim strImageName As String = "dir/img1.jpg" '*** for Sub Directory

            BitmapImage image = new BitmapImage();
            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
            string isoFilename = strImageName;
            Stream stream = isoStore.OpenFile(isoFilename, System.IO.FileMode.Open);
            image.SetSource(stream);
            this.ImageFull.Source = image;
            stream.Close();

        }
    }
}

ในตัวอย่างนี้มี Code ทั้งที่เป็น VB.NET และ C# และสามารถดาวน์โหลด All Code ทั้งหมดได้จากส่วนท้ายของบทความ (Login สมาชิกก่อน)

Screenshot

Windows Phone Image Source From  Isolated Storage

แสดง Image Source ที่อยู่ใน Isolated Storage

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-09-15 11:46:00 / 2017-03-25 22:24:55
  Download : Download  Windows Phone Image Source From  Isolated Storage (Application Storage)
 Sponsored Links / Related

 
Windows Phone and Isolated Storage (Application Storage)
Rating :

 
Windows Phone ListBox Image Binding and Resource from Isolated Storage (Application Storage)
Rating :

 
Windows Phone Play MP3 or Video MediaElement from Isolated Storage (Application Storage)
Rating :

 
Windows Phone Copy Transfer file from PC Between Isolated Storage (Application Storage)
Rating :

 
Windows Phone Download Save file to Isolated Storage (Application Storage)
Rating :

 
Windows Phone Create and Write Text File In Isolated Storage (Application Storage)
Rating :

 
Windows Phone Read Text File in Isolated Storage (Application Storage)
Rating :

 
Windows Phone Delete / Remove File In Isolated Storage (Application Storage)
Rating :

 
Windows Phone List Show File In Isolated Storage (Application Storage)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่