Jumat, 28 November 2014

WindowsPhone 8.1: Now UniversalWrapPanel is an alternative for WrapPanel(C#-XAML)

Introduction:

Still i am really addicted for 'WrapPanel'.Because WrapPanel is great for laying out things in a vertical or horizontal orientation until you reach the edge of the container and then moving on to the next column or row.But unfortunately i found 'WrapPanal' is no longer supported by windows store apps(i.e Universal Apps).Yestereday i found 'UniversalWrapPanel' is an alternative for 'WrapPanel'  layout .And i am heartly says very thanks to @gregstoll for making UniversalWrapPanel.However in this post i am going to explain about UniversalWrapPanel.

Building the sample:

  • Make sure you’ve downloaded and installed the Windows Phone SDK. For more information, see Get the SDK.
  • I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
  • This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows.

Description:

Previously in windowsphone 8.0,WrapPanel control is available from Microsoft.Phone.Controls.Toolkit.dll.WrapPanel is a good layout for positioning child elements sequentially from left to right or top to bottom. When elements extend beyond the panel edge, they are positioned in the next row or column.Unfortunately now WrapPanel is not supported by windows store apps.And so we need an alternative for 'WrapPanel' in windows store apps (i.e UniversalWrapPanel).Ok all right lets start to knowing about new control with following steps.

Step 1:
  • Open Visual Studio 2013
  • Create new project using the "Blank App" template available under Visual C# -> Store Apps -> Windows Phone Apps. (Ex: "WrapPanel8.1")
Install UniversalWrapPanel for Windows Phone 8.1, run the following command in the Package Manager Console
PM> Install-Package UniversalWrapPanel
After that you will be found 'UniversalWrapPanel' dll in references like this
Step 2:
Open MainPage.xaml and add the namespace in xaml:
  1. xmlns:UniversalWrapPanel="using:Gregstoll"  
Step 3:
Lets Write following xaml code to use UniversalWrapPanel
  1. <Grid Background="#FF59ABB4">  
  2.         <Grid.RowDefinitions>  
  3.             <RowDefinition Height="Auto"/>  
  4.             <RowDefinition Height="Auto"/>  
  5.             <RowDefinition Height="Auto"/>  
  6.             <RowDefinition Height="Auto"/>  
  7.         </Grid.RowDefinitions>  
  8.         <TextBlock FontSize="25" Text="Horizontal UniversalWrapPanel:"/>  
  9.         <!--Horizontal Panel-->  
  10.         <UniversalWrapPanel:UniversalWrapPanel Grid.Row="1" Orientation="Horizontal" Background="#FF34AC21">  
  11.             <Button Content="Button1" />  
  12.             <Button Content="Button2" />  
  13.             <Button Content="Button3" />  
  14.             <Button Content="Button4" />  
  15.             <Button Content="Button5" />  
  16.         </UniversalWrapPanel:UniversalWrapPanel>  
  17.         <TextBlock FontSize="25" Grid.Row="2" Text="Vertical UniversalWrapPanel:"/>  
  18.         <!--Vertical Panel-->  
  19.         <UniversalWrapPanel:UniversalWrapPanel Background="#FFC500FF" Grid.Row="3" Orientation="Vertical">  
  20.             <Button Content="Button1" />  
  21.             <Button Content="Button2" />  
  22.             <Button Content="Button3" />  
  23.             <Button Content="Button4" />  
  24.             <Button Content="Button5" />  
  25.         </UniversalWrapPanel:UniversalWrapPanel>  
  26.     </Grid> 

ScreenShots:

Summary:
From this article we have learned how to use UniversalWrapPanel in Windows Phone 8.1.And i hope you don't need to source code file from me,because of necessary code is available in this post.

FeedBack Note:
Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)

Rabu, 26 November 2014

WindowsPhone: Image crop with rectangle ,Beginners Tutorials (C#-XAML)

Introduction:

Especially for photo apps,we may need to crop the image with rectangle which is little bit difficult to implement through the code.However i will explained very clearly in this post with help of WriteableBitmap .

Requirements:

This sample is targeted to windowsphone 7.1 OS

Description:

In this sample i was cropped the image with rectangle,and then saved it to 'MedialLibrary'.So lets start the development by following steps.
Step 1:
  • Open Visual Studio
  • Create new project name(Ex: "ImageCropWithRect")
Step 2:
Open MainPage.xaml and add following xaml code.
XAML

<Grid x:Name="LayoutRoot" Background="White"
        <Grid.RowDefinitions
            <RowDefinition Height="Auto"/> 
            <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
        <!--ContentPanel - place additional content here--> 
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid> 
        <StackPanel Orientation="Vertical"
            <TextBlock HorizontalAlignment="Center" FontSize="30" Text="Image Crop with Recatngle" Foreground="#FF17CDC4"/> 
            <Rectangle Margin="0,5,0,0" Height="0.5" Fill="#FF17CDC4" /> 
            <Canvas Height="300" Margin="5" x:Name="canvas" Width="480"
                <!--Original Image--> 
                <Image Width="470" Stretch="Uniform" Name="OriginalImage" Source="/Assets/Nature1.jpg" MouseLeftButtonDown="OriginalImage_MouseLeftButtonDown" MouseLeftButtonUp="OriginalImage_MouseLeftButtonUp" MouseMove="OriginalImage_MouseMove"/> 
                <!--Rectangle to be used for Crop Original Image--> 
                <Rectangle x:Name="rect" StrokeThickness="4" Stroke="#FFEA18A7"></Rectangle> 
            </Canvas> 
            <Button Name="CropBtn" Content="CropImage" Background="#FF3CD3CC" Click="CropBtn_Click" /> 
            <!--Cropped Image--> 
            <Image Stretch="None" Name="FinalCroppedImage"/> 
            <Button Name="SaveBtn" Visibility="Collapsed" Content="Save to Gallery" Background="#FF3CD3CC" Click="SaveBtn_Click" /> 
        </StackPanel> 
    </Grid>
In above code In Canvas layout I added two child controls(OriginalImage,rect).Here 'rect' is used for crop the 'OriginalImage' with rectangle shape.So when click the 'CropBtn' ,selected rectangle area of OriginalImage source will be set to 'FinalCroppedImage'.And cropped image will be saved to media library when you click on 'SaveBtn' .However you will be understand the above code by moving to further important steps.
Step 2:
To crop image ,we need to (x, y) co-ordinates and the height & width of the cropped image.On MouseEvents of 'OriginalImage' get the Poin1,Point2 values to make image crop with rectangle shape.
C#

       //Mouse Move 
        private void OriginalImage_MouseMove(object sender, MouseEventArgs e) 
        { 
            Point2 = e.GetPosition(OriginalImage); 
        } 
        //Mouse Up 
        private void OriginalImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
        { 
            Point2 = e.GetPosition(OriginalImage); 
        } 
        //Mouse Down 
        private void OriginalImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
        { 
            Point1 = e.GetPosition(OriginalImage);//Set first touchable coordinates as point1 
            Point2 = Point1; 
            rect.Visibility = Visibility.Visible;           
        }
And draw the dynamic rectangle on mouse move of 'OriginalImage'
C#

Point Point1, Point2; 
 public MainPage() 
        { 
            InitializeComponent(); 
            //fire when render frame 
            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); 
         } 
private void CompositionTarget_Rendering(object sender, EventArgs e) 
        { 
            //Used for rendering the cropping rectangle on the image. 
            rect.SetValue(Canvas.LeftProperty, (Point1.X < Point2.X) ? Point1.X : Point2.X); 
            rect.SetValue(Canvas.TopProperty, (Point1.Y < Point2.Y) ? Point1.Y : Point2.Y); 
            rect.Width = (int)Math.Abs(Point2.X - Point1.X); 
            rect.Height = (int)Math.Abs(Point2.Y - Point1.Y); 
        }

Step 3:

Make sure to set 'WriteableBitmap' with OrgianlImage on PageLoad.

C#

WriteableBitmap WB_CapturedImage;//for original image 
WriteableBitmap WB_CroppedImage;//for cropped image 
public MainPage() 
        { 
            InitializeComponent(); 
            //fire when render frame 
            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); 
            this.Loaded+=MainPage_Loaded; 
        } 
        private void MainPage_Loaded(object sender, RoutedEventArgs e) 
        { 
            //Set WriteableBitmap with OrgianlImage 
            WB_CapturedImage = new WriteableBitmap(OriginalImage, null); 
        }

Step 4:

Get the cropped image area when click on 'CropBtn' and set it to 'FinalCroppedImage'.


C#

private void CropBtn_Click(object sender, RoutedEventArgs e) 
        { 
            // Get the size of the source image 
            double originalImageWidth = WB_CapturedImage.PixelWidth; 
            double originalImageHeight = WB_CapturedImage.PixelHeight; 
 
            // Get the size of the image when it is displayed on the phone 
            double displayedWidth = OriginalImage.ActualWidth; 
            double displayedHeight = OriginalImage.ActualHeight; 
 
            // Calculate the ratio of the original image to the displayed image 
            double widthRatio = originalImageWidth / displayedWidth; 
            double heightRatio = originalImageHeight / displayedHeight; 
 
            // Create a new WriteableBitmap. The size of the bitmap is the size of the cropping rectangle 
            // drawn by the user, multiplied by the image size ratio. 
            WB_CroppedImage = new WriteableBitmap((int)(widthRatio * Math.Abs(Point2.X - Point1.X)), (int)(heightRatio * Math.Abs(Point2.Y - Point1.Y))); 
 
            // Calculate the offset of the cropped image. This is the distance, in pixels, to the top left corner 
            // of the cropping rectangle, multiplied by the image size ratio. 
            int xoffset = (int)(((Point1.X < Point2.X) ? Point1.X : Point2.X) * widthRatio); 
            int yoffset = (int)(((Point1.Y < Point2.Y) ? Point1.Y : Point2.X) * heightRatio); 
 
            // Copy the pixels from the targeted region of the source image into the target image,  
            // using the calculated offset 
            if (WB_CroppedImage.Pixels.Length > 0
            { 
                for (int i = 0; i < WB_CroppedImage.Pixels.Length; i++) 
                { 
                    int x = (int)((i % WB_CroppedImage.PixelWidth) + xoffset); 
                    int y = (int)((i / WB_CroppedImage.PixelWidth) + yoffset); 
                    WB_CroppedImage.Pixels[i] = WB_CapturedImage.Pixels[y * WB_CapturedImage.PixelWidth + x]; 
                } 
 
                // Set the source of the image control to the new cropped image 
                FinalCroppedImage.Source = WB_CroppedImage; 
                SaveBtn.Visibility = Visibility.Visible; 
                 
            } 
            else 
            { 
                FinalCroppedImage.Source = null
                SaveBtn.Visibility = Visibility.Collapsed; 
            } 
            //rect.Visibility = Visibility.Collapsed; 
        }

Step 5:

Finally save cropped image to MediaLibary when click on 'SaveBtn'.

C#

private void SaveBtn_Click(object sender, RoutedEventArgs e) 
        { 
            try 
            { 
                String tempJPEG = "CroppedImage.jpg"
                //Create virtual store and file stream. Check for duplicate tempJPEG files. 
                var myStore = IsolatedStorageFile.GetUserStoreForApplication(); 
                if (myStore.FileExists(tempJPEG)) 
                { 
                    myStore.DeleteFile(tempJPEG); 
                } 
                IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG); 
                //Encode the WriteableBitmap into JPEG stream and place into isolated storage. 
                Extensions.SaveJpeg(WB_CroppedImage, myFileStream, WB_CroppedImage.PixelWidth, WB_CroppedImage.PixelHeight, 085); 
                myFileStream.Close(); 
                //Create a new file stream. 
                myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read); 
 
                //Add the JPEG file to the photos library on the device. 
                MediaLibrary library = new MediaLibrary(); 
                Picture pic = library.SavePicture("SavedPicture.jpg", myFileStream); 
                MessageBox.Show("Cropped image saved successfully to media library!"); 
                myFileStream.Close(); 
            } 
            catch 
            { 
                MessageBox.Show("Error on image saving!"); 
            } 
        }

Note:

1)You need to add a reference to the Microsoft.Xna.Framework in the references of your project.

2)Make sure you have the ID_CAP_MEDIALIB turned on in your WMAppManifest.xml file.

Result:



ImageCrop

FeedBack Note:
Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)



Selasa, 25 November 2014

Cara Mengoptimalkan Blog dengan Dasar dan Rencana Yang Baik


Cara Mengoptimalkan Blog dengan Dasar dan Rencana Yang Baik

BLOGGINGPASURUAN- Artikel kali ini tentang Cara Mengoptimalkan Blog dengan Dasar dan Rencana Yang Baik, saya akan memberikan planning apa saja yang harus di lakukan untuk mengoptimalkan website anda. Sobat harus mempertimbangkan metode SEO bahkan sebelum memulai membuat sebuah Blog. karena optimasi mempengaruhi setiap bagian dari Blog Sobat termasuk desain, pengembangan, fungsi dan struktur. Jika sobat blogger tidak mengambil metode untuk mengoptimalkan konten blog dan file, yang di kenal sebagai On-Page SEO

Fungsi Blog yang User Friendly

Sebagai istilah yang lebih terkait dengan desain sisi situs berkembang, namun sebenarnya sangat penting karena sekali penguinjung menemukan apa yang mereka butuhkan di situs web, mereka akan tetap distus untuk waktu yang lama. Jika pengguna puas dengan situs web, mereka akn menyimpannya sebagai favorit

Struktur URL

Nama file HTML harus mudah untuk mensin pencari untuk mengidentifikasi kata kunci dan kategori, sebagai contoh jika Sobat memiliki halaman yang berbicara tentang Cara Optimalkan Blog. Sobat dapat memberi nama file HTML Cara Optimalkan Blog. HTML dan pengunjung dapat mencapai melalui www.bloganda.com/ Cara-Optimalkan-Blog.html.

Struktur Desain Blog

Salah satu hal penting untuk di pertimbangkan adalah desain website. desain bersih dengan gambar di optimalkan dapat memuatcepat dan mesin pencari bisa merangkak lebih cepat dari pada website dengan gambar berukuran besar, yang butuh waktu lama untuk meload. juga fleksibel desain yang dapat dimodifikasi dengan mudah memungkinkan anda untuk menyesuaikan situs web anda.

Navigasi Blog

Navigasi sangat penting untuk searc engine dan halaman website harus dihubungkan satu sama lain sehingga pengguna dapat dengan mudah mencapai halaman apapun pada website dari halaman lain disitus sebuah halaman web yang tidak memungkinkan anda untuk menavigasi ke lain halaman disebut dead link. dead link adalah caara yang buruk di industri SEO. cara terbaik untuk menyatukan halaman situs web anda adalah membuat menu yang terletak pada setiap halaman web yang pengunjung dapat digunakan untuk link kehalaman lain dalam website.

Fungsi SEO di dalam Blog

Ketika anda membuat sebuah website, harus mempertimbangkan fungsi yang membantu proses SEO. misalnya anda dapat menambahkan bagian bawah setiap posting atau area konten yang memberitahu pengguna tentang topik yang terkait pada website. kemudian mereka dapat mengunjungi kontenuntuk topik yang terkait dan mendapatkan informasi lebih lanjut. hal ini membantu meningkatkan tampilan halaman website anda dan wktu pengguna menghabiskan waktu di website Sobat.

Semoga bermanfaat…