Code :
public void addTexture (Image _texture, Point _pGHaut, Point _pDHaut, int _yBas, boolean _transform ) { if(_pGHaut.getX()>_pDHaut.getX()) { Point BufPoint = _pDHaut; _pDHaut = _pGHaut; _pGHaut = BufPoint; _texture = Image. createImage(_texture, 0, 0, _texture. getWidth(), _texture. getHeight(), Sprite. TRANS_MIRROR); } if(_pGHaut.getY()>=_yBas || _pDHaut.getY()>_yBas || _yBas > this.__height) { return; } else { if(_transform==true) _texture = Image. createImage(_texture, 0, 0, _texture. getWidth(), _texture. getHeight(), Sprite. TRANS_MIRROR); Image textDeforme = deformerImage (_texture, _pDHaut. getX()-_pGHaut. getX(), _yBas-_pGHaut. getY(), _yBas-_pDHaut. getY()); int x = _pGHaut.getX(); int y = 0; if(_pGHaut.getY()>_pDHaut.getY()) y = _pDHaut.getY(); else y = _pGHaut.getY(); afficherImage(textDeforme, x, y); } } public Image deformerImage (Image _image, int _largeur, int _hauteur1, int _hauteur2 ) { int oldWidth = _image.getWidth(); int oldHeight = _image.getHeight(); int[] oldImage = readImage(_image); int cas = 0; double dy = 0.0; int air = 0; int larg = 0; if(_hauteur1>_hauteur2) { cas = 1; dy = ((double)_hauteur1-(double)_hauteur2)/(double)oldWidth; air = oldWidth*_hauteur1; larg = (oldWidth*(_hauteur1-1)); } else { dy = ((double)_hauteur2-(double)_hauteur1)/(double)oldWidth; air = oldWidth*_hauteur2; larg = (oldWidth*(_hauteur2-1)); } int lon = (oldWidth*(oldHeight-1)); double newHauteur = (double)_hauteur1; int[] newImage = new int[air]; int[] bufImTab = null; for(int i=0; i<oldWidth; i++) { bufImTab = new int[oldHeight]; //recupe tout une bande de hauteur for(int j=0;j<oldHeight;j++) bufImTab[j] = oldImage[i+lon -(j*oldWidth)]; //On la redimensionne bufImTab = readImage (redimImage (Image. createRGBImage(bufImTab, 1, oldHeight, true), 1, (int)newHauteur )); //On la place dans la nouvelle image for(int k=0;k<(int)newHauteur;k++) { if(newImage[k]==0) newImage[k] = defineColor(0,0,0,0); newImage[i+larg-(k*oldWidth)] = bufImTab[k]; } if(cas == 0) newHauteur +=dy; else newHauteur -=dy; } if(cas==1) { return redimImage (Image. createRGBImage(newImage, oldWidth, _hauteur1, true),_largeur, _hauteur1 ); } else { return redimImage (Image. createRGBImage(newImage, oldWidth, _hauteur2, true),_largeur, _hauteur2 ); } } public Image redimImage (Image _image, int _longueur, int _hauteur ) { int sourceWidth = _image.getWidth(); int sourceHeight = _image.getHeight(); int redimWidth = _longueur; int redimHeight = _hauteur; int[] oldImage = readImage(_image); int[] newImage = new int[redimWidth*redimHeight]; int compteur =0; Image redimImage = Image. createImage(redimWidth, redimHeight ); if(redimWidth > __width) redimWidth = __width; if(redimHeight > __height) redimHeight = __height; if (redimHeight < 0) redimHeight = redimWidth * sourceHeight / sourceWidth; for (int y = 0; y < redimHeight; y++) { for (int x = 0; x < redimWidth; x++) { int dx = x * sourceWidth / redimWidth; int dy = y * sourceHeight / redimHeight; newImage[compteur] = oldImage[dx+dy*sourceWidth]; compteur++; } } redimImage = Image. createRGBImage(newImage, redimWidth, redimHeight, true); return redimImage; } public void afficherImage (Image _image, int _x, int _y ) { int[] imData = readImage(_image); int width = _image.getWidth(); int height = _image.getHeight(); int compteurX = 0; int compteurY = 0; if(_x+_image.getWidth() > __width || _y+_image.getHeight() > __height ) { System. out. println("PROBLEME AFFICHER IMAGE" ); return; } for(int i=_y;i<(height+_y);i++) { for(int j=_x;j<(width+_x);j++) { if(0 <= _x && _x <= this.__width && 0 <= _y && _y <= this.__height) this.__tabJeux[j+(i*this.__width)] = imData[compteurX+compteurY*width]; compteurX++; } compteurX = 0; compteurY++; } } public int[] readImage (Image _image ) { int[] argbdata = new int[_image.getWidth()*_image.getHeight()]; _image.getRGB( argbdata, 0, _image.getWidth(), 0, 0, _image.getWidth(), _image.getHeight()); return argbdata; }
|