The Naked Kitchen
http://v.youku.com/v_show/id_XNzQwNzc3NDQ=.html
小朴 21:20:24
当你站在我旁边的瞬间 你的眼神很迷人 虽然昨天哭了 但是今天因为你而活着 明天因为你而幸福 不是你的美貌 只是需要一个温暖的爱 过去的岁月就让它过去吧 忘掉他 没有你 我什么都做不了 除了爱你我什么都不知道
小朴 21:20:42
这首歌叫 除了爱,我什么都不知道
“除了爱你 我什么都不知道”
http://v.youku.com/v_show/id_XNzQwNzc3NDQ=.html
母猪猪 21:20:24
当你站在我旁边的瞬间 你的眼神很迷人 虽然昨天哭了 但是今天因为你而活着 明天因为你而幸福 不是你的美貌 只是需要一个温暖的爱 过去的岁月就让它过去吧 忘掉他 没有你 我什么都做不了 除了爱你我什么都不知道
母猪猪 21:20:42
这首歌叫 除了爱,我什么都不知道

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on 2010-6-27, 16:42:06
*
*/
package newpackage;
import java.awt.FileDialog;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.image.AreaAveragingScaleFilter;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
/**
*
* @author 野猪
*/
public class NewJFrame extends javax.swing.JFrame {
int[][] desPixels;
static BufferedImage bi0;
Graphics2D big;
Image im1;
File file_choosed;
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("选择文件夹");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("合并");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2))
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 314, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(44, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(183, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int returnVal = fc.showOpenDialog(this);
file_choosed = fc.getSelectedFile();
if(!file_choosed.isDirectory())
this.jLabel1.setText("请选择文件夹");
else
Image_Combine(file_choosed);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
FileDialog savedialog=new FileDialog(this,"保存图型到JPG格式",FileDialog.SAVE);
savedialog.setVisible(true);
if(savedialog.getFile()!=null){
try{
String pathStr = savedialog.getDirectory();
pathStr = pathStr.replace("\\", "\\\\");
String path = pathStr + savedialog.getFile();
ImageIO.write(bi0, "png", new File(path));
}catch(Exception ee){
ee.printStackTrace();
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
public void Image_Combine(File filename){
String[] fileList=filename.list();
int count_jpg=0;//要合成的图片数
List<String> jpgfile=new ArrayList<String>();
for(String str:fileList){
if(str.endsWith(".jpg")){
count_jpg++;
jpgfile.add(this.file_choosed.getAbsolutePath()+"\\"+str);
}
}
int count_raw=0;
if(count_jpg%8==0)
count_raw=count_jpg/8;
else count_raw=count_jpg/8+1;//合成图片的行数
//合并图像
int flag_count=-1;//这是第几张图片
int[] srcPixels=new int[128*96];
desPixels=new int[count_raw*96][1024];
for(int i=0;i<jpgfile.size();i++){
Image im=Toolkit.getDefaultToolkit().getImage(jpgfile.get(i));
MediaTracker tracker=new MediaTracker(this);
tracker.addImage(im, 0);
try{
tracker.waitForID(0);
}catch(InterruptedException e){
e.printStackTrace();
}
Image im_src=this.Image2fit(im);
flag_count++;
try{
PixelGrabber pg=new PixelGrabber(im_src,0,0,128,96,srcPixels,0,128);
pg.grabPixels();
}catch(InterruptedException e){
e.printStackTrace();
}
Pixels2Des(srcPixels,flag_count);
}
int[] pix=new int[count_raw*96*1024];
for(int i=0;i<count_raw*96;i++){
for(int j=0;j<1024;j++){
pix[i*1024+j]=desPixels[i][j];
}
}
try{
im1=createImage(new MemoryImageSource(1024, count_raw*96, pix, 0, 1024));
}catch(Exception e){
e.printStackTrace();
}
bi0=new BufferedImage(1024,count_raw*96,BufferedImage.TYPE_INT_ARGB);
big=bi0.createGraphics();
big.drawImage(im1, 0, 0, this);
}
//将每张图像的像素写入目的数组
public void Pixels2Des(int[] srcPixels,int flag_count){
int width=128;
int height=96;
int flag_col=flag_count%8;
int flag_raw=flag_count/8;
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
desPixels[flag_raw*96+i][flag_col*128+j]=srcPixels[i*width+j];
}
}
}
//将文件变为合适的大小
public Image Image2fit(Image im){
Image im2;
AreaAveragingScaleFilter filter=new AreaAveragingScaleFilter(128,96);
FilteredImageSource fis=new FilteredImageSource(im.getSource(),filter);
im2=createImage(fis);
return im2;
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
浙公网安备 33010602011771号