Image View With WPF
Ane Iseng-iseng mencari pekerjaan menggantikan tidur siang…dan akhirnya membuat Aplikasi sederhana
tentang membuat aplikasi Image View dengan menggunakan WPF dan sedikit codingan C#..
Ayo Kita Mulai Saja :
Pertama Buka Visual Studio anda
Buat Project baru, pilih WPF Application
Pada bagian formnya, drag and drop aja 1 buah label, 1 button dan Image (semua ini pada bagian Toolbox).
Gambar Program Yang Ane Buat :
Dibawah Ini Codingan Xaml nya :
<Window x:Class="LookPhoto.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="App Photo" Height="605" Width="658"> <Grid Height="548"> <Image Height="423" HorizontalAlignment="Left" Margin="12,12,0,0" Name="image_view" Stretch="Fill" VerticalAlignment="Top" Width="612" SnapsToDevicePixels="True" /> <Button Content="Browse" Height="28" HorizontalAlignment="Right" Margin="0,441,280,0" Name="btn_browse" VerticalAlignment="Top" Width="75" Click="btn_browse_Click" /> <Label Background="AliceBlue" Height="28" HorizontalAlignment="Left" Margin="12,441,0,0" Name="lbl_nama_file" VerticalAlignment="Top" Width="263" /> </Grid> </Window>
Dan dibawah Ini Codingan di C# nya :
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
image_view.Source = new BitmapImage(new Uri("tes.jpg", UriKind.Relative));
}
private void btn_browse_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog img = new Microsoft.Win32.OpenFileDialog();
img.InitialDirectory = "c:\";
img.Filter = "Image files (*.jpg)|*.jpg|(*.png)|*.png|All Files (*.*)|*.*";
img.RestoreDirectory = true;
Nullable<bool> result = img.ShowDialog();
if (result == true)
{
string selectedFileName = img.FileName;
lbl_nama_file.Content = selectedFileName;
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(selectedFileName);
bitmap.EndInit();
image_view.Source = bitmap;
}
}
}
}
Kembangkan Ilmu anda ya…^^
Source Codenya dapat diDownload disini
thank’s for http://www.c-sharpcorner.com
Categories: Project Simple [Q]
Tags: Image View - Wpf









