下面列出了怎么用sun.awt.image.MultiResolutionImage的API类实例代码及写法,或者点击链接到github查看源代码。
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image)
.getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
private CImage createFromImage(final Image image, final boolean prepareImage) {
if (image instanceof MultiResolutionImage) {
List<Image> resolutionVariants
= ((MultiResolutionImage) image).getResolutionVariants();
return createFromImages(resolutionVariants, prepareImage);
}
int[] buffer = imageToArray(image, prepareImage);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}
private CImage createFromImage(final Image image, final boolean prepareImage) {
if (image instanceof MultiResolutionImage) {
List<Image> resolutionVariants
= ((MultiResolutionImage) image).getResolutionVariants();
return createFromImages(resolutionVariants, prepareImage);
}
int[] buffer = imageToArray(image, prepareImage);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}
private CImage createFromImage(final Image image, final boolean prepareImage) {
if (image instanceof MultiResolutionImage) {
List<Image> resolutionVariants
= ((MultiResolutionImage) image).getResolutionVariants();
return createFromImages(resolutionVariants, prepareImage);
}
int[] buffer = imageToArray(image, prepareImage);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}
private CImage createFromImage(final Image image, final boolean prepareImage) {
if (image instanceof MultiResolutionImage) {
List<Image> resolutionVariants
= ((MultiResolutionImage) image).getResolutionVariants();
return createFromImages(resolutionVariants, prepareImage);
}
int[] buffer = imageToArray(image, prepareImage);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}
private CImage createFromImage(final Image image, final boolean prepareImage) {
if (image instanceof MultiResolutionImage) {
List<Image> resolutionVariants
= ((MultiResolutionImage) image).getResolutionVariants();
return createFromImages(resolutionVariants, prepareImage);
}
int[] buffer = imageToArray(image, prepareImage);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}
private CImage createFromImage(final Image image, final boolean prepareImage) {
if (image instanceof MultiResolutionImage) {
List<Image> resolutionVariants
= ((MultiResolutionImage) image).getResolutionVariants();
return createFromImages(resolutionVariants, prepareImage);
}
int[] buffer = imageToArray(image, prepareImage);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
return;
}
String icon = "NSImage://NSApplicationIcon";
final Image image = Toolkit.getDefaultToolkit().getImage(icon);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Icon does not have resolution variants!");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
int width = 0;
int height = 0;
for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
int rvWidth = resolutionVariant.getWidth(null);
int rvHeight = resolutionVariant.getHeight(null);
if (rvWidth < width || rvHeight < height) {
throw new RuntimeException("Resolution variants are not sorted!");
}
width = rvWidth;
height = rvHeight;
}
}