Maybe this might help....it lets you do a lot in the way of how you want it
layed out on the panel, including alpha....hth, Ike
/**
* This version uses a default alpha blend of 0% of the previous image,
100% of current image
* @param g the Graphics2D context
* @param blitmode 1=raw at its natural size in upper left of picture at
UpperLeftX,UpperLeftY
* 2=draw at its natural size in center(UpperLeftX,UpperLeftY not used
in blitMode==2)
* 3=draw at its natural size tiled throughout
* 4=scale it all into the view window, aspect ratio be damned
* 5=scale it all into view, but maintain aspect ratio
* 6=like 4&5 but do not scale it, use actual size
* Note - methods 4,5 and 6 tile based on where you are in the window,
1,2 and 3 do not
* @param img the image to blit
*@param UpperLeftX the left corner to put the image in
*@param UpperLeftY the upper corner to put the image in
*@param targWidth the width of the image after blitting
*@param targHeight the heigh of the image after blitting
*@param observer the ImageObserver itself
*/
final static public void blit(Graphics2D g,int blitMode,Image img,int
UpperLeftX, int UpperLeftY,int targWidth,int targHeight, ImageObserver
observer){
blit(g,blitMode,img,UpperLeftX, UpperLeftY,targWidth,targHeight,
1.0F,1.0F,observer);
}
/**
*
* @param g the Graphics2D context
* @param blitmode 1=raw at its natural size in upper left of picture at
UpperLeftX,UpperLeftY
* 2=draw at its natural size in center(UpperLeftX,UpperLeftY not used
in blitMode==2)
* 3=draw at its natural size tiled throughout
* 4=scale it all into the view window, aspect ratio be damned
* 5=scale it all into view, but maintain aspect ratio
* 6=like 4&5 but do not scale it, use actual size
* Note - methods 4,5 and 6 tile based on where you are in the window,
1,2 and 3 do not
* @param img the image to blit
*@param UpperLeftX the left corner to put the image in
*@param UpperLeftY the upper corner to put the image in
*@param targWidth the width of the image after blitting
*@param targHeight the heigh of the image after blitting
*@param alpha the percentage (0.0f - 1.0f, inclusive) of the current
image (img) to use
*@param observer the ImageObserver itself
*/
final static public void blit(Graphics2D g,int blitMode,Image img,int
UpperLeftX, int UpperLeftY,int targWidth,int targHeight, float alpha,
ImageObserver observer){
blit(g,blitMode,img,UpperLeftX, UpperLeftY,targWidth,targHeight,
alpha,1.0F, observer);
}
/**
*
* @param g the Graphics2D context
* @param blitmode 1=raw at its natural size in upper left of picture at
UpperLeftX,UpperLeftY
* 2=draw at its natural size in center(UpperLeftX,UpperLeftY not used
in blitMode==2)
* 3=draw at its natural size tiled throughout
* 4=scale it all into the view window, aspect ratio be damned
* 5=scale it all into view, but maintain aspect ratio
* 6=like 4&5 but do not scale it, use actual size
* Note - methods 4,5 and 6 tile based on where you are in the window,
1,2 and 3 do not
* @param img the image to blit
*@param UpperLeftX the left corner to put the image in
*@param UpperLeftY the upper corner to put the image in
*@param targWidth the width of the image after blitting
*@param targHeight the heigh of the image after blitting
*@param alpha the percentage (0.0f - 1.0f, inclusive) of the current
image (img) to use
*@param alphaOver the percentage (0.0f - 1.0f, inclusive) of the images
to be painted over this bitmap to use
*@param observer the ImageObserver itself
*/
final static public void blit(Graphics2D g,int blitMode,Image img,int
UpperLeftX, int UpperLeftY,int targWidth,int targHeight, float alpha, float
alphaOver, ImageObserver observer){
g.setComposite(AlphaComposite.getInstance(AlphaCom posite.SRC_OVER,alpha));
if (blitMode==1){
//draw at its natural size in upper left of picture at
UpperLeftX,UpperLeftY
g.drawImage(img,UpperLeftX,UpperLeftY,observer);
}else if (blitMode==2){
//draw at its natural size in center
//UpperLeftX,UpperLeftY not used in blitMode==2
float x = (float)(img.getWidth(observer));
float y = (float)(img.getHeight(observer));
float tWidth=(float) targWidth;
float tHeight=(float) targHeight;
tWidth=tWidth/2-x/2;
tHeight=tHeight/2-y/2;
if(x>0.0 && y>0.0)
g.drawImage(img,UpperLeftX+(int)tWidth,UpperLeftY+ (int)tHeight,observer);
}else if (blitMode==3){
//draw at its natural size tiled throughout
int x = img.getWidth(observer);
int y = img.getHeight(observer);
int xcount,ycount;
xcount=ycount=1;
if(x>0 && y>0){
while (x*xcount<targWidth+x){
while (y*ycount<targHeight+y){
g.drawImage(img,x*(xcount-1),y*(ycount-1),observer);
ycount++;
}
ycount=1;
xcount++;
}
}
}else if (blitMode==4){
//scale it all into the view window, aspect ratio be damned
g.drawImage(img,UpperLeftX,UpperLeftY,UpperLeftX+t argWidth,UpperLeftY+targHe
ight, observer);
}else if(blitMode>4){
//scale it all into the view - tries to get most of it in the
view without changing the aspect ratio
float xratio, yratio;
float x = (float)(img.getWidth(observer));
float y = (float)(img.getHeight(observer));
float tWidth=(float) targWidth;
float tHeight=(float) targHeight;
if(x>0.0 && y >0.0){
if(blitMode==5){
xratio = x/tWidth;
yratio = y/tHeight;
}else{
xratio=yratio=1.0f;
}
// x&y are width & height of picture file rect
// tWidth & tHeight are width & height of target rect
if(xratio <= yratio){
g.drawImage(img,UpperLeftX,UpperLeftY,
/*ulx+*/(int)(x/xratio),/* uly+*/(int)(y/xratio) , observer);
}else{
g.drawImage(img,UpperLeftX,UpperLeftY,
/*ulx+*/(int)(x/yratio), /*uly+*/(int)(y/yratio), observer);
}
}else{
g.drawImage(img,UpperLeftX,UpperLeftY,/*ulx+*/targWidth,/*uly+*/targHeight,
observer);
}
}
//set alpha back so controls can draw
g.setComposite(AlphaComposite.getInstance(AlphaCom posite.SRC_OVER,alphaOver)
);
}