2017-05-09 15 views
0

次のコードを書いたが、写真は並んでいないマトリックスの形でなければならない。写真を行列形式の写真に変換する

私の目標は、キャンバスの最後に空白を残さないことです。

import java.awt.Color; 
 
public class aaa { 
 
    public static Color karstr (Color x,Color y,double lambda){ 
 
     int r= (int)((1-lambda)*x.getRed()+lambda*y.getRed()); 
 
     int g= (int)((1-lambda)*x.getGreen()+lambda*y.getGreen()); 
 
     int b= (int)((1-lambda)*x.getBlue()+lambda*y.getBlue()); 
 

 
     return new Color (r,g,b); 
 
    } 
 

 
    public static void main(String[] args) { 
 
     int genilik =50; 
 
     int ykseklik=100; 
 
     Picture p=new Picture("c:/data/a.jpg"); 
 
     Picture q=new Picture("c:/data/b.jpg"); 
 
     Picture r= new Picture(p.width()+400,p.height()+10); 
 

 
     for (int i = 0; i < p.width(); i++) 
 
      for (int j = 0; j < p.height(); j++) { 
 
       Color x=p.get(i, j); 
 
       Color y=q.get(i,j); 
 

 
       r.set(i*genilik/p.width(),j*ykseklik/p.height(), x); 
 
       Color c=karstr(x,y,(double)1/5); 
 
       r.set(i*genilik/p.width()+50,j*ykseklik/p.height(), c); 
 
       Color a=karstr(x,y,(double)1/4); 
 
       r.set(i*genilik/p.width()+100,j*ykseklik/p.height(),a); 
 
       Color b=karstr(x,y,(double)1/3); 
 
       r.set(i*genilik/p.width()+150,j*ykseklik/p.height(),b); 
 
       Color f=karstr(x,y,(double)1/2); 
 
       r.set(i*genilik/p.width()+200,j*ykseklik/p.height(),f); 
 
       Color g=karstr(x,y,(double)1/1.2); 
 
       r.set(i*genilik/p.width()+250,j*ykseklik/p.height(),g); 
 
       r.set(i*genilik/p.width()+300,j*ykseklik/p.height(), y); 
 
      } 
 
     r.show(); 
 
    } 
 
}

+0

主な質問:N-1個の中間フレームを使用して、image1.jpgからimage2.jpgにフェージング、アニメーション効果をもたらします。私を助けてください! – arheznes

+0

したがって、出力は実際にピクチャの配列ですか? –

答えて

0
import java.awt.Color; 
public class PhotoTransformation { 
    private Picture source; 
    private Picture dest; 

    public PhotoTransformation(Picture source, Picture dest) { 
    source = source; 
    dest = dest; 
    } 

    public static void main(String[] args) { 
    Picture p=new Picture("c:/data/a.jpg"); 
    Picture q=new Picture("c:/data/b.jpg"); 

    PhotoTransformation photoTransformation = new PhotoTransformation(p, q); 
    Picture[] photoSeries = photoTransformation.produceTransformationPhotos(8); 

    // Show the photos 

    } 

    public Picture[] produceTransformationPhotos(int transitionPhotoNumber) { 
    int photoNumber = transitionPhotoNumber + 2; 
    Picture[] photos = new Picture[photoNumber]; 

    int width = source.width(); 
    int height = source.height(); 

    for (int p = 0; p < photoNumber; p++) { 
     Picture newPhoto = new Picture(width, height); 
     photos[p] = newPhoto; 

     for (int i = 0; i < width; i++) { 
     for (int j = 0; j < height; j++) { 
      Color sourceColor = source.get(i, j); 
      Color destColor = dest.get(i, j); 
      double weight = (double) p/(double) (photoNumber - 1); 

      Color transformationColor = produceWeightedMeanColor(sourceColor, destColor, weight); 
      newPhoto.set(i, j, transformationColor); 
     } 
     } 
    } 

    return photos; 
    } 

    private static Color produceWeightedMeanColor(Color x, Color y, double weight) { 
    int r = (int)((1-weight) * x.getRed() + weight * y.getRed()); 
    int g = (int)((1-weight) * x.getGreen() + weight * y.getGreen()); 
    int b = (int)((1-weight) * x.getBlue() + weight * y.getBlue()); 

    return new Color(r,g,b); 
    } 
}