Sunday, June 3, 2012



DOWNSAMPLE AN IMAGE AND GET ITS BIT PATTERNS

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
 import java.math.BigInteger;
import javax.imageio.ImageIO;

public class Dwnsampletst {

private static final int IMG_WIDTH = 25;   //set height n width of image
private static final int IMG_HEIGHT = 20;

public static void main(String [] args){

try{

BufferedImage originalImage = ImageIO.read(new File("img.jpg"));  //ur source image
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();

BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File("img1.jpg"));   //downsampled image


   
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ImageIO.write(resizeImageJpg, "png", baos);

byte[] val = baos.toByteArray();
          BigInteger bi = new BigInteger(val);
    String s =  bi.toString(2);
System.out.println(s);      //get the bit pattern of downsampled  image



}catch(IOException e){
System.out.println(e.getMessage());
}

    }

    private static BufferedImage resizeImage(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();

return resizedImage;
    }

  }

downsample an image using awt

DownSample An Image



import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;



public class Dwnsample {

private static final int IMG_WIDTH = 768;
private static final int IMG_HEIGHT = 520;

public static void main(String [] args){

try{

BufferedImage originalImage = ImageIO.read(new File("rose.jpg"));  //give ur image name here
int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();

BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg", new File("rose1.jpg"));  // ur downsampled image name



BufferedImage resizeImageHintJpg = resizeImageWithHint(originalImage, type);
ImageIO.write(resizeImageHintJpg, "jpg", new File("rose3.jpg")); 



}catch(IOException e){
System.out.println(e.getMessage());
}

    }

    private static BufferedImage resizeImage(BufferedImage originalImage, int type){
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();

return resizedImage;
    }

   


Saturday, July 30, 2011

Static methods Cannot be Over-ridden

U cannot over-ride the static method.If u do so the compiler wont give u ny error but the behaviour would certainly not the same.
Example

class T
{
static void  mth()
{
System.out.println("hiii static");
}

}
class Test extends T
{
static void mth()
{
System.out.println("overridding method");
}
public static void main(String []args)
{
Test.mth();
T.mth();
mth();
T obj=new Test();
obj.mth(); // here u should get d output as "overidding method " bt we get "hii static" as our output
}

}

Tuesday, July 26, 2011

Setting the classpath for first java Program

Step1:
right clk on computers->properties->advance system settings->environment variables.

Step2:
click on environment variables->classpath.



Step3:
After selecting classpath option,click on edit.
Step 4:
with adding semicolon at the end ,give the path upto bin where ur jdk is located.
click on OK.
Step 5:
Check ur settings by writing javac on command prompt.

Friday, July 22, 2011

Starting with struts in netbeans 6.5

To Start with first download the following plugins:

"org-netbeans-modules-web-frameworks-struts2.nbm" 
"org-netbeans-modules-web-frameworks-struts2lib20011.nbm"

Step 1


click on tools and click on plug-ins.

Under the option of downloaded plugin,browse the location where u hav stored ur plug-in and then click on OK. (tools->plug-ins->downloaded->open->finish)
Step 2:
Click on file and new  Project.


(File->new Project->java Web)
select the java Web ,Click Next.
Step 3: Choosing Web Server
Choose the web server.
netbeans have inbulit support of glassfish server.


Step 4:
Click on next.
then select the option Struts 2 .

Step 5:
Click on Finish.

Sunday, July 17, 2011

welcome

hiiiii..if someone wants ny help related to java can post here..