代码
- public static Image makeImageInLocation(Image smallImg, int location, Color fillColor, Point size) {
- if (size.x<=0||size.y<=0) {
- return null;
- }
- Image img = new Image(smallImg.getDevice(), size.x, size.y);
- GC gc = new GC(img);
- img.setBackground(fillColor);
- Rectangle smImgBounds = smallImg.getBounds();
- switch (location) {
- case MIDDLE:
- gc.drawImage(smallImg, size.x / 2, size.y / 2);
- break;
- case LEFT_BOTTOM:
- gc.drawImage(smallImg, size.x - smImgBounds.width - 1, size.y - smImgBounds.height - 1);
- break;
- case LEFT_TOP:
- gc.drawImage(smallImg, size.x - smImgBounds.width - 1, 1);
- break;
- case RIGHT_BOTTOM:
- gc.drawImage(smallImg, 1, size.y - smImgBounds.height - 1);
- break;
- case RIGHT_TOP:
- gc.drawImage(smallImg, 1, 1);
- break;
- default:
- break;
- }
- gc.dispose();
- return img;
- }
- public static final int MIDDLE = 0;
- public static final int LEFT_BOTTOM = 1;
- public static final int LEFT_TOP = 2;
- public static final int RIGHT_BOTTOM = 3;
- public static final int RIGHT_TOP = 4;
public static Image makeImageInLocation(Image smallImg, int location, Color fillColor, Point size) {
if (size.x<=0||size.y<=0) {
return null;
}
Image img = new Image(smallImg.getDevice(), size.x, size.y);
GC gc = new GC(img);
img.setBackground(fillColor);
Rectangle smImgBounds = smallImg.getBounds();
switch (location) {
case MIDDLE:
gc.drawImage(smallImg, size.x / 2, size.y / 2);
break;
case LEFT_BOTTOM:
gc.drawImage(smallImg, size.x - smImgBounds.width - 1, size.y - smImgBounds.height - 1);
break;
case LEFT_TOP:
gc.drawImage(smallImg, size.x - smImgBounds.width - 1, 1);
break;
case RIGHT_BOTTOM:
gc.drawImage(smallImg, 1, size.y - smImgBounds.height - 1);
break;
case RIGHT_TOP:
gc.drawImage(smallImg, 1, 1);
break;
default:
break;
}
gc.dispose();
return img;
}
public static final int MIDDLE = 0;
public static final int LEFT_BOTTOM = 1;
public static final int LEFT_TOP = 2;
public static final int RIGHT_BOTTOM = 3;
public static final int RIGHT_TOP = 4;