Write a method to overlap two pictures vertically using an AlphaComposite object.
What will be an ideal response?
```
public void overlapPicturesVert ( Picture p1 ,
Picture p2 ,
int startOverlap )
{
int amountOverlap = p1 . getHeight () - startOverlap;
// get the Graphics2D object
Graphics g = this.getGraphics ( ) ;
Graphics2D g2 = (Graphics2D) g ;
// draw p1 up to overlap point
g2. setComposite (
AlphaComposite . get Instance (AlphaComposite .SRC OVER,
( float ) 1 . 0f ) ) ;
g2 . drawImage ( p1. getImage ( ) ,
0 ,0, p1.getWidth ( ), startOverlap,
0,0, p1.getWidth ( ), startOverlap,
null );
// draw p1 in the overlap area ( replace background )
g2 . drawImage ( p1.getImage ( ) ,
0 , startOverlap ,
p1.getWidth ( ) , p1. getHeight ( ) ,
0 , startOverlap ,
p1.getWidth ( ) , p1. getHeight ( ) ,
null ) ;
// set the composite to blend the old and new pixels
// 50%
g2 . setComposite (
AlphaComposite.get Instance (AlphaComposite .SRC OVER,
0 . 5 f ) ) ;
g2 . drawImage ( p2 . getImage ( ) ,
0 , startOverlap , p2 . getWidth ( ) , p1 . getHeight ( ) ,
0 ,0 , p2.getWidth ( ) , amountOverlap , nul l ) ;
// draw p2 after the overlap
g2 . setComposite (
AlphaComposite . get Instance (AlphaComposite .SRC OVER,
( f loat ) 1 . 0f ) ) ;
g2 . drawImage ( p2 . getImage ( ) ,
0 , p1 . getHeight ( ) , p2 . getWidth ( ) ,
p1 . getHeight ( ) + p2 . getHeight ( ) - amountOverlap ,
0 , amountOverlap , p2 . getWidth ( ) , p2 . getHeight ( ) ,
nul l ) ;
}
```
You might also like to view...
The standards for XML are developed and maintained by _____.
A. NASA B. the NSF C. the W3C D. DARPA
Recursion is:
(a) the ability of a program to repeat a block of code (b) the ability of a method to call itself (c) the ability of a method to call smaller methods (d) the ability of a method to implement factorials
When a numeric field is added to a PivotTable, it is placed in the ________ area of the PivotTable field list
A) Report Filter B) Row Labels C) Column Labels D) Values
You can turn off grammar checking by ____.
A. pressing [F7] B. clicking the Check grammar check box to remove the checkmark C. opening the AutoCorrect Exceptions dialog box D. opening the AutoCorrect dialog box