Reklam Alanı
Reklam Alanı
Bilim Teknoloji

Applying Sketch Effect by using Nokia Imaging SDK

 

 

After you created a new Project and installed Nokia Imaging SDK , copy an paste codes below.

You will see two ApplicationBarButton , do not forget change rotation as a Landscape.


<!–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>
<!–Original and Filtered Images–>
<Grid x:Name=”ContentPanel” Grid.Row=”1″>
<Grid.Background>
<ImageBrush Stretch=”Fill” ImageSource=”/resimler/wallpaper22.jpg”/>
</Grid.Background>
<Image Name=”beray1″ HorizontalAlignment=”Left” Height=”470″ Margin=”10,0,0,0″ VerticalAlignment=”Top” Width=”350″ />
<Image Name=”beray2″ HorizontalAlignment=”Left” Height=”468″ Margin=”365,2,0,0″ VerticalAlignment=”Top” Width=”349″/>
</Grid>
</Grid>
<!–AppBarButtons–>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible=”True” IsMenuEnabled=”False” BackgroundColor=”Black” Opacity=”0.7″ ForegroundColor=”White”>
<shell:ApplicationBarIconButton IconUri=”/resimler/Folder.png” x:Name=”gallerybutton” Text=”Open” Click=”ApplicationBarIconButton_Click”/>
<shell:ApplicationBarIconButton IconUri=”/resimler/Save.png” x:Name=”savebutton” Text=”Save” Click=”ApplicationBarIconButton_Click_1″/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

wp_ss_20140426_0003[1]

 

Now you must add codes below to your MainPage.cs page. With these codes , you will be able to pick an image , save and use filter.

At the first , copy replace codes below ;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using abc.Resources;(Replace abc with your Project name)
using System.Windows.Media.Imaging;
using Nokia.Graphics.Imaging;
using Microsoft.Phone.Tasks;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using Nokia.InteropServices.WindowsRuntime;
using Windows.Storage.Streams;
using Microsoft.Xna.Framework.Media;

If there is no error , continue to copy and paste.

privateFilterEffect ketch = null;
//We’ve createad two writeable bitmap image to be able to use filter
privateWriteableBitmap beray1bitmap = null;
privateWriteableBitmap beray2bitmap = null;

public MainPage()

{

InitializeComponent();
beray1bitmap = newWriteableBitmap((int)beray1.Width, (int)beray1.Height);
beray2bitmap = newWriteableBitmap((int)beray2.Width, (int)beray2.Height);

}

privatevoid ApplicationBarIconButton_Click(object sender, EventArgs e)

{
PhotoChooserTask chooser = newPhotoChooserTask();
chooser.Completed += PickImageCallback;
chooser.Show();
}
privateasyncvoid PickImageCallback(object sender, PhotoResult e)
{
if (e.TaskResult != TaskResult.OK || e.ChosenPhoto == null)
{
return;
}
try
{
beray2bitmap.SetSource(e.ChosenPhoto);
beray1.Source = beray1bitmap;
beray1bitmap.SetSource(e.ChosenPhoto);
// Rewind stream to start.           

e.ChosenPhoto.Position = 0;
var imageStream = newStreamImageSource(e.ChosenPhoto);
sketch = newFilterEffect(imageStream);
var sketchfilter = newSketchFilter();
sketch.Filters = new[] { sketchfilter };
// Render the image to a WriteableBitmap.
var renderer = newWriteableBitmapRenderer(sketch, beray2bitmap);
beray2bitmap = await renderer.RenderAsync();
beray2.Source = beray2bitmap;
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
return;
}
}
privateasyncvoid ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
if (sketch == null)
{
return;
}
var jpegRenderer = newJpegRenderer(sketch);
// Jpeg renderer gives the raw buffer for the filtered image.
IBuffer jpegOutput = await jpegRenderer.RenderAsync();
// Save the image as a jpeg to the saved pictures album.
MediaLibrary library = newMediaLibrary();
string fileName = string.Format(“BerayEfekt_{0:G}”, DateTime.Now);
var picture = library.SavePicture(fileName, jpegOutput.AsStream());
MessageBox.Show(“Image Saved”);
}
}
}
Everything’s fine run and the results of the Project :

wp_ss_20140426_0002[1]

Additionally , you can download Project by clicking here

> Windows Phone 8 – 8.1 hakkında daha fazla yazı için: Tıklayın.  <

Hayati Kdrgl {Hayati}

hayaleturk.com kurucusu ve tasarımcısı