A. java中BufferedImage图像有哪几种类型
Java的BufferedImage类是Image类的子类。属于一种类型,它是用来处理和操作的图像数据。
B. java中的ImageIcon类在哪个包里
java中的ImageIcon类在Serializable, Accessible, Icon包里。
作用:它根据 Image 绘制 Icon。可使用 MediaTracker 预载根据 URL、文件名或字节数组创建的图像,以监视该图像的加载状态。
里面是相对于你创建的image类的,路径是相对于image类文件的,所以要把图片文件和image.classs类文件放在一起。
简单性:
Java看起来设计得很像C++,但是为了使语言小和容易熟悉,设计者们把C++语言中许多可用的特征去掉了,这些特征是一塌启般程序员很少使用的。例如,Java不支持goto语句,代之以提供break和continue语句以及异常处理。
Java还剔除了C++的操作符过载(overload)和多继承特征,并且不使用主文件,免去了预处理程序。因为Java没有结构,数组和串都是对象,所以不需要指针。Java能够自动处理对象的指衫宏引用和间接引用,实现自动的无用唯册单元收集,使用户不必为存储管理问题烦恼,能更多的时间和精力花在研发上。
C. image类型怎么初始化java
ava image类初始化
java image类初始化,无法初始化类javax.imageio.ImageIO
科普君冷知识
转载
关注
0点赞·753人阅读
我试图将一个
spring web应用程序部署到运行在
windows azure上的生产环境中的tomcat 7(尝试过ubuntu和windows datacenter vm).
遗憾的是,我在生成与
ImageIo一起使用的缩略图时检索到错误(下面的堆栈跟踪).
在开发过程中,我也使用了tomcat 7,所以我真的不明白,生产网络服务器有什么不同.
当我尝试通过“ImageIO.scanForPlugins();”加载模块时exakt同样的事情发生了.是不是ImageIO或javax.awt通常包含在标准的java7 jre中?
我想在META-INF / services / javax.io中设置一个子文件夹或者在堆模式下运行jvm,但没有解决下面的问题.我想我现在真的走在墙上,因为我不知道如何解决这个问题.在本地开发环境(Windows 8,Java7 64B,Tomcat7)上,我没有对上面的这些提示做任何事情(堆模式或类文件),并且一切都运行完美.有这样的事情,应用程序是在没有GPU或类似的服务器上运行的吗?
感谢您提前回复=)
HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIOException report
Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi..doFilter(.java:54)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication..doFilter(.java:183)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context..doFilter(.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO
ch.yooapps.resman.service.data.FileServiceImpl.createFile(FileServiceImpl.java:63)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.aop.support.AopUtils.(AopUtils.java:319)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
com.sun.proxy.$Proxy171.createFile(Unknown Source)
ch.yooapps.resman.application.controllers.rest.FileController.attacheFile(FileController.java:61)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi..doFilter(.java:54)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication..doFilter(.java:183)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context..doFilter(.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
来自Tomcatlog的Stacktrace:
SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/rp] threw exception [Handler processing failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
java.lang.NullPointerException
at javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:155)
at javax.imageio.ImageIO.(ImageIO.java:65)
at ch.yooapps.resman.service.data.FileServiceImpl.createFile(FileServiceImpl.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy47.createFile(Unknown Source)
at ch.yooapps.resman.application.controllers.rest.FileController.attacheFile(FileController.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi..doFilter(.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication..doFilter(.java:183)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context..doFilter(.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
D. 关于java里image的用法
先要设置图片路径,我们将一将背景图片back.jpg放到C盘的img目录下,调用语句如下:
ImageIcon icon=new ImageIcon("C:\\img\\back.jpg),一定要是双反斜杠
然后分别在JComponent里添加图片
JFrame
利用JFrame的一个方法setIconImage(Image image);
由于要用到Image类,所以还得把上面定义的ImageIcon对象转换成Image对象:
Image image=icon.getImage();
然后就可以调用JFrame的setIconImage(image)方法了。
还要注意一点的是,由于有些图片的格式JVM不能识别,所以要转格式,一般为jpg,gif.如把.bmp格式的转换为.jpg,不能简单的把后缀名改了就行,这样照样不能显示。方法很简单,直接用WINDOWS自带的画图工具打开图片,然后另存为时改为.jpg或.gif格式就可以了。
附源代码
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JTree;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.awt.FlowLayout;
public class ImageTest extends JFrame{
ImageIcon icon=new ImageIcon("c:\\img\\system.jpg");
Image image=icon.getImage();
public ImageTest()
{
JMenuBar mb=new JMenuBar();
this.setJMenuBar(mb);
JMenu menu=new JMenu("system");
menu.setIcon(icon);
//JMenuItem item=new JMenuItem("exit",icon);
JMenuItem item=new JMenuItem(icon);
item.setIcon(icon);
JLabel label=new JLabel(icon);
//label.setIcon(icon);
menu.add(item);
mb.add(menu);
DefaultMutableTreeNode root=new DefaultMutableTreeNode();
DefaultMutableTreeNode node1=new DefaultMutableTreeNode();
DefaultMutableTreeNode node11=new DefaultMutableTreeNode();
DefaultMutableTreeNode node12=new DefaultMutableTreeNode();
DefaultMutableTreeNode node2=new DefaultMutableTreeNode();
DefaultMutableTreeNode node21=new DefaultMutableTreeNode();
root.add(node1);
root.add(node2);
node1.add(node11);
node1.add(node12);
node2.add(node21);
JTree jTree1 = new javax.swing.JTree(root);
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setOpenIcon(new ImageIcon("C:\\img\\down.jpg")); //展开时节点图标
renderer.setClosedIcon(new ImageIcon("C:\\img\\file.jpg")); //折叠时节点图标
renderer.setLeafIcon(new ImageIcon("C:\\img\\man_small.jpg")); //叶子节点图标
jTree1.setCellRenderer(renderer);
this.add(label);
this.setIconImage(image);
this.add(jTree1);
this.setDefaultCloseOperation(3);
this.setLocation(300,400);
this.pack();
this.setVisible(true);
}
public static void main(String[] args)
{
new ImageTest();
}
}
E. java如何为image类型赋值
image数据类型是sqlserver中用来存贮变长的二进制数据,取值范围在跟int数据类型一样,所以在java中对应的数据类型可以是int,因为是二进制,也可以试试byte[],具体是int还是byte[]好,我没用过,你可以试试。
F. 在java的image图片类中画线怎么画
importjava.awt.*;
classMyCanvasextendsCanvas{
publicvoidpaint(Graphicsg){
g.setFont(newFont("华文行楷",Font.PLAIN,20));
g.setColor(Color.RED);
g.drawString("绘图测试!",20,20);
g.drawLine(30,60,100,60);
g.setColor(Color.BLUE);
g.draw3DRect(60,50,70,30,false);
g.setColor(Color.BLUE);
g.fillArc(0,60,65,65,40,80);
g.setFont(newFont("华文彩云",Font.PLAIN,30));
g.setColor(Color.PINK);
g.drawString("彩云之南",20,120);
}
}
publicclassAWTDrawing{
publicstaticvoidmain(Stringargs[]){
Framef=newFrame("AWT绘图");
MyCanvasp=newMyCanvas();
f.add(p);
f.setSize(170,170);
f.setBackground(newColor(160,220,220));
f.setVisible(true);
}
}
效果图(该网站bug315上面还有很多java相关的知识,你可以去学习一下呵呵):
G. java中ImageIcon和Image的区别是什么
ImageIcon和Image的区别:
ImageIcon:
ImageIcon位于javax.swing包中。可以根据Image绘制Icon(这句话很关键),可以使用MediaTracker预载图像(Image也可以)
构造方法不少,举几个常用的:
ImageIcon(Image image);
ImageIcon(String name);
ImageIcon(URL url);
Image:
来自于java.awt包中,抽象类Image是表示图形图像的所有类的超类,必须以特定于平台的方式获取图像。
它的主要方法是:
Image getScaledInstance(int width,int height,int hints)
H. java.awt.Image类的setScaleInstance()方法是怎样定义的,参数是什么
public Image getImage(URL url, String name)
返回能被绘制到屏幕上的 Image 对象。url 参数必须指定绝对 URL。name 参数是相对于 url 参数的说明符。
不管图像存在与否,此方法总是立刻返回。当此 applet 试图在屏幕上绘制图像时,数据将被加载。绘制图像的图形图元将逐渐绘制到屏幕上。
参数:
url - 给出图像基本位置的绝对 URL。
name - 相对于 url 参数的图象位置。
返回:
指定 URL 处的图像。
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
绘制指定图像中当前可用的图像。图像的左上角位于该图形上下文坐标空间的 (x, y)。图像中的透明像素不影响该处已存在的像素。
此方法在任何情况下都立刻返回,甚至在图像尚未完整加载,并且还没有针对当前输出设备完成抖动和转换的情况下也是如此。
如果图像已经完整加载,并且其像素不再发生更改,则 drawImage 返回 true。否则,drawImage 返回 false,并且随着更多的图像可用或者到了绘制动画另一帧的时候,加载图像的进程将通知指定的图像观察者。
I. Java里Image数据类型怎么传参数给他
传Image对象
获取Image对象方式有很多如以下
Image img = Toolkit.getDefaultToolkit.createImage(String filename);
Image img = Toolkit.getDefaultToolkit.createImage(URL url);
Image img = ImageIO.read(File file);
Image img = ImageIO.read(URL url);
J. java.awt.Image类
public Image getImage(URL url, String name)
返回能被绘制到屏幕上的 Image 对象。url 参数必须指定绝对 URL。name 参数是相对于 url 参数的说明符。
不管图像存在与否,此方法总是立刻返回。当此 applet 试图在屏幕上绘制图像时,数据将被加载。绘制图像的图形图元将逐渐绘制到屏幕上。
参数:
url - 给出图像基本位置的绝对 URL。
name - 相对于 url 参数的图象位置。
返回:
指定 URL 处的图像。
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
绘制指定图像中当前可用的图像。图像的左上角位于该图形上下文坐标空间的 (x, y)。图像中的透明像素不影响该处已存在的像素。
此方法在任何情况下都立刻返回,甚至在图像尚未完整加载,并且还没有针对当前输出设备完成抖动和转换的情况下也是如此。
如果图像已经完整加载,并且其像素不再发生更改,则 drawImage 返回 true。否则,drawImage 返回 false,并且随着更多的图像可用或者到了绘制动画另一帧的时候,加载图像的进程将通知指定的图像观察者。
参数:
img - 要绘制的指定图像。如果 img 为 null,则此方法不执行任何操作。
x - x 坐标。
y - y 坐标。
observer - 转换了更多图像时要通知的对象。
返回:
如果图像像素仍在更改,则返回 false;否则返回 true。