package resize;
import javax.swing.*;
public class pro {
int w,h;
int[][] memor=new int[2500][2500];
int[][] memog=new int[2500][2500];
int[][] memob=new int[2500][2500];
int[][] sampler=new int[500][500];
int[][] sampleg=new int[500][500];
int[][] sampleb=new int[500][500];
int size;
int mx,nx;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
sizecheck("d.jpg");
catchimg sub=new catchimg();
sub.w=w;
sub.h=h;
sub.makedata("d.jpg");
memor=sub.memor;
memog=sub.memog;
memob=sub.memob;
size=w;
if(h>w)size=h;
int w1,h1,z;
for(mx=0;mx<500;mx++){
for(nx=0;nx<500;nx++){
w1=size*nx/500;
h1=size*mx/500;
z=0;
if(w1>w-1)z=100;
if(h1>h-1)z=100;
sampler[mx][nx]=255;
sampleg[mx][nx]=255;
sampleb[mx][nx]=255;
if(z<50)sampler[mx][nx]=memor[h1][w1];
if(z<50)sampleg[mx][nx]=memog[h1][w1];
if(z<50)sampleb[mx][nx]=memob[h1][w1];
}
}
graph sub4=new graph();
sub4.sampler=sampler;
sub4.sampleg=sampleg;
sub4.sampleb=sampleb;
sub4.makedata("r.jpg");
}
void sizecheck(String str){
ImageIcon icon = new ImageIcon(str);
h = icon.getIconHeight();
w = icon.getIconWidth();
}
}
package resize;
import java.awt.*;
import java.awt.Color;
import java.awt.image.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.Polygon;
class graph{
int h=500;
int w=500;
int[][] sampler=new int[500][500];
int[][] sampleg=new int[500][500];
int[][] sampleb=new int[500][500];
void makedata(String file){
int w1,h1,mx,nx;
w1=w;
h1=h;
BufferedImage off = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_BGR);
Graphics offsc = off.getGraphics();
int z;
offsc.setColor(Color.white);
offsc.fillRect(0,0,500,500);
for(mx=0;mx<h;mx++){
for(nx=0;nx<w;nx++){
offsc.setColor(new Color(sampler[mx][nx],sampleg[mx][nx],sampleb[mx][nx]));
offsc.fillRect(nx,mx,1,1);
}
}
offsc.dispose();
try {
ImageIO.write(off, "jpeg", new File(file));
} catch (IOException exception) { exception.printStackTrace(); }
}
}
package resize;
import java.awt.*;
import java.awt.image.*;
import java.net.URL;
import java.net.MalformedURLException;
public class catchimg {
PixelGrabber pg;
Color col;
Image img;
int red,green,blue;
int mx,nx,m,n;
int ex,ey;
String s1,s2,s3,s4;
URL urlx;
int w;
int h;
int[] pix=new int[2500*2500];
int[][] memor=new int[2500][2500];
int[][] memog=new int[2500][2500];
int[][] memob=new int[2500][2500];
void makedata(String pic){
catchimg(pic);
}
void catchimg(String s){
img = Toolkit.getDefaultToolkit().getImage(s);
pg = new PixelGrabber(img,0,0,w,h,pix,0,w);
try{pg.grabPixels();}catch(InterruptedException ie){}
m=0;
n=0;
for(int i=0;i<w*h;i++){
int p = pix[i];
col=new Color(pix[i]);
red=col.getRed();
green=col.getGreen();
blue=col.getBlue();
memor[m][n]=red;
memog[m][n]=green;
memob[m][n]=blue;
n=n+1;
if (n==w)m=m+1;
if (n==w)n=0;
}
}
}
最終更新:2014年04月18日 10:45