We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi, I'm trying to put an image into another. is delimited, lines to the area where the image is going to fit. but the result is not very good. how to solve this?
PImage cover,Cov; // The source image
PrintWriter output;
void setup() {
cover = loadImage("cover_overlay.png"); // Load the image
Cov = loadImage("SLUS_213.69_COV.png"); // Load the image
output = createWriter("positions.txt");
size(cover.width,cover.height, P2D);
}
int[] P1 = {113, 6};
int[] P2 = {9, 152};
int[] P3 = {132, 203};
int[] P4 = {234, 25};
int incre=0;
float[] rectas(int P1[],int P2[],int P3[],int P4[],int x ) {
float m1= (float)(P1[1]-P2[1])/(P1[0]-P2[0]);
float m2= (float)(P2[1]-P3[1])/(P2[0]-P3[0]);
float m3= (float)(P1[1]-P4[1])/(P1[0]-P4[0]);
float m4= (float)(P3[1]-P4[1])/(P3[0]-P4[0]);
float r1= m1*x+ P2[1] ;
float r2= m2*x+ P2[1] ;
float r3= m3*x+ P1[1]-20;/// -20 ??
float r4= m4*x+ P3[1]+240 ;// `240??
float[] rValsY={r1,r2,r3,r4};
return rValsY; // Returns an array
}
int cont=0;
int buff[]=new int[56475];
void draw() {
background(0);
println("X="+mouseX+" Y="+ mouseY);
PImage Out = createImage(cover.width, cover.height, ARGB);
Out.loadPixels();
for (int y = 0; y < Out.height; y++) {
for (int x = 0; x < Out.width; x++) {
float r1[] =rectas( P1,P2,P3,P4,x );
int Y0 = int (x)+ (int)r1[0] * (Out.width);
int Y1 = int (x)+ (int)r1[1] * (Out.width);
int Y2 = int (x)+ (int)r1[2] * (Out.width);
int Y3 = int (x)+ (int)r1[3] * (Out.width);
int Index = int (x)+ (int)y * (Out.width);
if( (Index>Y0) && (Index<Y1) && (Index>Y2) && (Index<Y3)){
int Y=(int) map(y,0,Out.height,0,Cov.height);
int X=(int) map(x,0,Out.width,0,Cov.width);
int C = X + Y * Cov.width;
Out.pixels[Index]=Cov.pixels[C];
}
}//end for x
} //end for y
Out.updatePixels();
image(Out,0,0);
image(cover,0,0);
}
cover-image 1: cover
Cov- image 2: Cov
Answers
that's the general idea but it's a lot less work and a better quality result if you were to use texture() - just tell it the coords of the corners of the box and let processing do all the hard maths.
http://processing.org/reference/texture_.html