biskuteri-cafe-JKomasto2/ImageApi.java

74 lines
1.8 KiB
Java

/* copyright
This file is part of JKomasto2.
Written in 2022 by Usawashi <usawashi16@yahoo.co.jp>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
copyright */
import javax.swing.ImageIcon;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.MediaTracker;
import java.awt.Graphics;
import java.awt.Component;
import java.awt.image.ImageObserver;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.net.MalformedURLException;
interface
ImageApi {
public static Image
local(String name)
{
String path = "graphics/" + name + ".png";
URL url = ImageApi.class.getResource(path);
if (url == null) return null;
return new ImageIcon(url).getImage();
}
public static Image
remote(String urlr)
{
try
{
URL url = new URL(urlr);
Toolkit TK = Toolkit.getDefaultToolkit();
return TK.createImage(url);
}
catch (MalformedURLException eMu)
{
return null;
}
}
public static ImageIcon
iconRemote(String urlr)
{
if (urlr == null) return null;
try
{
return new ImageIcon(new URL(urlr));
}
catch (MalformedURLException eMu)
{
return null;
}
}
}