Save bytes Image in the Application Server Using java

import java.util.*;
import java.sql.*;
import java.lang.Integer;
import java.text.DecimalFormat;
import java.io.FileInputStream;
import java.io.*;
import java.text.*;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;
import java.awt.Dimension;

import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.model.Fill;
import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.model.TextBox;
//import org.apache.commons.codec.binary.Base64;
import org.apache.poi.hslf.HSLFSlideShow;

public class SaveImg
{

public DBConnection dbCon;
public Connection c;
public List finallist ;

public List arrList;

public List arrListBullet ;
public List arrListSpark ;

public Vector columnTypeCategorical;
public Vector columnTypeNumeric;

public String strCatFields=””;
public String strNumFields=””;

private SlideShow ppt;
private Slide slide;
private Fill fill;
private int idx;
private FileOutputStream out;

public static Vector vcFileName = new Vector();

public static int i=0;

public void ConnectDatabase()
{
dbCon = new DBConnection();
dbCon.ConnectDB();
c = dbCon.conn;
}

/**
@param -Query String
@return -array List
*/
public void SaveImages(byte[] bd, int width, int height)
{

BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
//loop through all the pixels
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
//calculate array offset
int o = (x*4)+(y*width*4);

//set the pixel color
//here we will need to convert
//the byte data to an unsigned
//value using &0xFF before passing
//it to the Color constructor
image.setRGB(x, y, new Color(
bd[o+1]&0xFF, //red
bd[o+2]&0xFF, //green
bd[o+3]&0xFF //blue
).getRGB());
}
}

//write the image to a file

String tomcatDir = System.getProperty("catalina.home");
File f = new File(tomcatDir+"/webapps/PP/Images/");

String strFileName = "img"+i;
File file = new File(tomcatDir+"/webapps/Images/"+strFileName+".bmp");
vcFileName.add(tomcatDir+"/webapps/Images/"+strFileName+".bmp");
i++;
try {ImageIO.write(image, "jpg", file);}
catch (IOException e) {e.printStackTrace();}
}

//empty default constructor
public void CreatePresentations()
{
try
{
CreatePresentation present = new CreatePresentation();
vcFileName.removeAllElements();
i=0;
}catch(Exception fnfe){}

}

/*public void createSlideWithChart(String chartName)
{
try
{
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
fill.setFillType(Fill.FILL_PICTURE);
idx = ppt.addPicture(new File(chartName), Picture.PNG);
fill.setPictureData(idx);
}catch(FileNotFoundException fnfe){}
catch(IOException ioe){}
}

public void savePPT()
{
try
{
ppt.write(out);
out.close();
}catch(FileNotFoundException fnfe){}
catch(IOException ioe){}
}*/

}

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

1 Response to Save bytes Image in the Application Server Using java

  1. vpn vs proxy says:

    Another example is when you use public Wi – Fi, knowing your wireless data can be
    sniffed out by criminals. Operates on multiple platforms: be sure that the provider you choose will support both Android VPN
    clients as well as i – Phone VPN clients. Check the connection again and see if the GUI steps
    are available.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s