Rufus is a utility that helps format and create bootable USB flash drives, such as USB keys/pendrives, memory sticks, etc. In my opinion Rofus is better than other utilities which does same, because it is easy to use. You can understand how to create bootable USB using Rofus from bellow screenshots.
JSON stands for JavaScript Object Notation.It is an independent data exchange format and is the best alternative for XML. This snippet will help you to parse JSON in Android.
JSONObject obj = tool.getJSONObject(); //You can use if the URL and Method is set. Else
JSONObject obj = tool.getJSONObject("http://10.0.2.2/json.php", params, "get");
Getting JSON String
String res = tool.getString(); //You can use if the URL and Method is set. Else
String res = tool.getString("http://10.0.2.2/json.php", params, "get");
Sample Code
package com.blogspot.terminal;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
TextView v;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
v = (TextView) findViewById(R.id.lbl);
new sendPostData().execute();
}
private class sendPostData extends AsyncTask<String, Void, String>
{
JSONTool jtool = new JSONTool();
String data;
@Override
protected String doInBackground(String... params) {
try{
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("name","Ajith"));
param.add(new BasicNameValuePair("mail","ajithkp560@gmail.com"));
JSONObject obj = jtool.getJSONObject("http://10.0.2.2/ajith/json.php", param, "post");
data = obj.getString("name")+" : "+obj.getString("email");
}catch(Exception e){
return new String("Exception: " + e.getMessage());
}
return data;
}
@Override
protected void onPostExecute(String result) {
//View your result here.
v.setText(result);
}
}
}
Hi guys... It is very simple program to parse an image and add new graphical components to image. Here I used Graphics2D package to add a rectangle to highlight face... Hope you enjoy this tutorial and share it with your friends.
VIDEO TUTORIAL
SOURCE CODE
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MarkImage extends JFrame {
JButton btn = new JButton("Open File");
JPanel imagePanel = new JPanel();
JPanel menuPanel = new JPanel();
double h, w;
MarkImage()//Constructor
{
super("Mark Image -- Coded By Ajith Kp [ ajithkp560 ]");
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
int ret = fc.showOpenDialog(MarkImage.this);
if(ret==JFileChooser.APPROVE_OPTION)
{
File imgf = fc.getSelectedFile();
imagePanel.removeAll();
try {
setPic(imgf);
} catch (IOException ex) {
}
}
}
});
menuPanel.add(btn);
add(menuPanel, BorderLayout.NORTH);
add(imagePanel, BorderLayout.CENTER);
}
public void setPic(File imgf) throws IOException
{
BufferedImage myImg = ImageIO.read(imgf);
double x = myImg.getWidth();
double y = myImg.getHeight();
h = imagePanel.getHeight();
w= imagePanel.getWidth();
if(x>w || y>h)
{
double ox = w/x, oy = h/y;
System.out.println(ox+" "+oy);
if(ox<oy)
{
x = x*ox;
y = y*ox;
}
else
{
x = x*oy;
y = y*oy;
}
}
Graphics2D g2 = myImg.createGraphics();
g2.setColor(Color.red);
g2.setStroke(new BasicStroke(20));
g2.drawRect(650, 220, 600, 600);
Image newimg = myImg.getScaledInstance((int)x, (int)y, Image.SCALE_SMOOTH);
JLabel picLabel = new JLabel(new ImageIcon(newimg));
imagePanel.add(picLabel);
imagePanel.revalidate();
imagePanel.repaint();
}
public static void main(String[] args) {
MarkImage dn = new MarkImage();
dn.setVisible(true);
dn.setSize(1200, 800);
dn.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}