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。