import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.*;

public class WinImage{
public Image scr;
public Graphics g;
public int wid,hei;
public int rc,gc,bc;
public int x,y;
public int scale = 0;

public WinImage(int wid,int hei){
this.wid = wid;
this.hei = hei;
scr = Image.createImage(wid,hei);
g = scr.getGraphics();
}

public void setPosition(int x,int y){
this.x = x;
this.y = y;
}

public void paint(Graphics h){
h.drawImage(scr,x,y,20);
}

public void setColor(int rc,int gc,int bc){
this.rc = rc;
this.gc = gc;
this.bc = bc;
g.setColor(rc,gc,bc);
}

public void drawImage(InputStream is,int x,int y){
try{
	Image img = Image.createImage(is);
	g.drawImage(img,x,y,20);
} catch (Exception e){}
}

public void line(int x,int y,int x2,int y2){
g.drawLine(x,y,x2,y2);
}

public void fillRect(int x,int y,int w,int h){
g.fillRect(x,y,w,h);
}

public void resize(int wid,int hei,int scale){
this.wid = wid;
this.hei = hei;
this.scale = scale;
if(scale==1){
	scr = resize_image(scr,wid,hei);
} else {
	Image temp = Image.createImage(wid,hei);
	g = temp.getGraphics();
	g.drawImage(scr,0,0,20);
	scr = temp;
}
}

//resize
public static Image resize_image(Image image, int i, int j)
{
int ai[] = new int[image.getWidth() * image.getHeight()];
image.getRGB(ai, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
int ai1[] = reescalaArray(ai, image.getWidth(), image.getHeight(), i, j);
Image image1 = Image.createRGBImage(ai1, i, j, true);
return image1;
}
private static int[] reescalaArray(int ai[], int i, int j, int k, int l)
{
int ai1[] = new int[k * l];
for(int i1 = 0; i1 < l; i1++)
{
int j1 = (i1 * j) / l;
for(int k1 = 0; k1 < k; k1++)
{
int l1 = (k1 * i) / k;
ai1[k * i1 + k1] = ai[i * j1 + l1];
}
}
return ai1;
}

}