Post Top Ad

May 24, 2014

How to Capture the screen selected by Current Form in WPF?

For my 3rd year project at SLIIT, we used WPF to develop the software. Once we wanated to get the selected part of the WPF current form as a image to be save in a separate locatioin. In WPF, the controls to handels the form is different than the normal winforms. So after searching hours in the internet, i came up with a solution.

Example output


WPF code

private void button5_Click(object sender, RoutedEventArgs e)

{
Image b = null;
int w = (int)this.Width;
int h = (int)this.Height;
System.Drawing.Size sz = new System.Drawing.Size((int)ActualWidth, 
       (int)ActualHeight);
System.Drawing.Point loc = new System.Drawing.Point((int)Left, (int)Top);

Hide();
System.Threading.Thread.Sleep(500);
 
using
(b = new Bitmap(w, h))
{
using
(Graphics g = Graphics.FromImage(b))
{
g
.CopyFromScreen(loc, new System.Drawing.Point(0, 0), sz);
}

Image x = new Bitmap(b);

ImageBrush myBrush = new ImageBrush();
x
.Save(@"C:\Users\Dell\Desktop\testImg.jpeg", ImageFormat.Jpeg);
myBrush
.ImageSource = new BitmapImage(new Uri(@"C:\Users\Dell\Desktop\
testImg.jpeg", 
            UriKind.Absolute));
this.Background = myBrush;

}
Show();
}
 
 

This code will extract the image taking the current form size as Width and Height and grab its content using Bitmap class. 











May 22, 2014

How to Check – Phone is Original or Fake ?

As replica phone are present in the market that looks similar to the original phone, to check whether your phone is original or fake there are two ways of checking it. These methods will help you a lot while buying a used cell phone.

First Check the following Features :

• Be careful about the spellings For example, Soniericsson, Nokla and Samsung
• Warranties:  Always insist on 12 months warranty certificate from the handset manufacturers; Never an oral agreement with the seller. Fake phones come with a shorter warranty periods since counterfeiters cannot guarantee it will last so long
• Check for performance of the handset: Some people carry their phones home without testing it first. Some dealers encourage this, knowing the handset is fake. As you check it out, you may notice some points of low performance such as memory which is smaller or poor quality photos.
• Appearances: like dull colors , Fake logos,built quality difference in weight, screen size, location of buttons and battery, quality of printing and paint finish, added or missing functions, quality control stickers and holograms and an overall lack of quality.
• The other method is checking Phones quality through 15 digit IMEI code :
• Dial *#06#

IMEI stands for International Mobile Equipment Identity. It is a 15-digit number and may be found in the packet of the mobile phone. It may also be found by removing the back cover and it may be placed on the battery sticker.
The number might be as below:
3 6 9 3 9 5 0 1 2 3 5 5 6 7 8

Now look at the 7th and 8th digit. These two digits will ensure your phone’s quality!

• If the seventh and eighth digits are 00 this indicates your cell phone is manufactured in Original Factory which ensures the best quality.
• If the seventh and eighth digits are 01 or 10 this indicates your cell phone is manufactured in Finland which is high quality.
• If the seventh and eighth digits are 13 this indicates your cell phone is assembled in Azerbaijan which is too bad. And it is also dangerous for health!
• If the seventh and eighth digits are 02 or 20 this indicates your cell phone is assembled in Emirates which is very poor quality. (NB: Some Indian sets have this number)
• If the seventh and eighth digits are either 03/30 04/40, this indicates your phone is made in China but its quality is good. But not good either as 00, 01 or 10.
• If the seventh and eighth digits are 05 or 50 this indicates your cell phone is manufactured either in Brazil or USA or Finland.
• If the seventh and eighth digits are 06 or 60 this indicates your cell phone is manufactured either in Hong Kong, or China or Mexico.
• If the seventh and eighth digits are 08 or 80 this indicates your cell phone is manufactured in Germany which is fair quality.

This will help you to pick the good one. Try it. But, remember, these tips may not work with the Sony Erickson Mobile Phone.
Though the above information has been collected from very reliable sources, 1 or 2 of them may slightly vary.

May 22, 2014

How to call a method after a delay in Android

I recently wanted to call a method after some time for my project. What i rally wanted was, i have already created a splash screen for my app. And then after 5seconds or so i wanted to remain it in active and start another activity.( in fact MainActivity).

public void DoSomething()
{
//do something here
}

IOS Approach For This Problem

Ex: In ios you will find a method called to do this task easilty
[self performSelector:@selector(DoSomething) withObject:nil afterDelay:5];
 

In Android what would be the best way to achieve this

I achieved this using java.util.concurrent package.

Here is the code

private static final ScheduledExecutorService worker = 
Executors.newSingleThreadScheduledExecutor();

void someMethod() {

Runnable task = new Runnable() {
public void run() {
/* Do something… */
}
};
worker
.schedule(task, 5, TimeUnit.SECONDS);
⋮
}
 
Note:
 
1. worker.schedule(task, 5, TimeUnit.SECONDS); 
   Here i have set the delay to 5 seconds. 
2. /* Do something… */
   Insert your code to be run there after the given time exceeds.   
 
 
 
 
 
May 21, 2014

Android 2nd Tutorial

Android Hello World Example



This is the most easy tutorial as far as android is concerned.





When you create a new project, by default Google has included hello world code for you. But what happens behind the code is the important part.
 
Summary steps to develop an Android application :
  1. Install Android SDK
  2. Install ADT Eclipse plugin
  3. Create an Android Virtual Device (AVD)
  4. Create Android Project with Eclipse (Wizard)
  5. Code it…
  6. Start it in Android Virtual Device (AVD)
In android all the code is normally written in Java
GUI is created using XML
So you have to attach GUI elements to the code. How we do this is via a file called R. R is a automatically generated file where you have all the default name for the elements which you have included in the GUI.
When you run the code what happen is all the components will be linked together with the code and display the output


But How come Hello world String appear in the GUI
Hello world string is in actually String file. 

String Resources

 A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings:
String

    XML resource that provides a single string.

String Array
    XML resource that provides an array of strings.

Quantity Strings (Plurals)
    XML resource that carries different strings for pluralization.
All strings are capable of applying some styling markup and formatting arguments. For information about styling and formatting strings.
Useful Links

Android Developer Guide

 



My Instagram