
import javaawtToolkit;
Toolkit tk=ToolkitgetDefaultToolkit();
Dimension screensize=tkgetScreenSize();
宽:screensizewidth
高:screensizeheight
图像的高度和宽度只有在图像被完全加载后才是有效的 ,你虽然已经把显示在frame上,可是你绝对是在没有完全加载时打印的!
/
Determines the width of the image If the width is not yet known,
this method returns <code>-1</code> and the specified
<code>ImageObserver</code> object is notified later
@param observer an object waiting for the image to be loaded
@return the width of this image, or <code>-1</code>
if the width is not yet known
@see javaawtImage#getHeight
@see javaawtimageImageObserver
/
public abstract int getWidth(ImageObserver observer);
你还是这样写吧,可以获取的:
URLClassLoader urlLoader = (URLClassLoader) TestImageclass
getClassLoader();
URL fileLoc = urlLoaderfindResource("images/gopng");
BufferedImage bi = javaximageioImageIOread(fileLoc);
Systemoutprintln(bigetWidth());//150
public class Ctianchong extends tool {
@Override
/
实现图像填充功能,从to中鼠标对应的一个位置将周围填充为颜色c
参数e表示鼠标事件,to表示对象,c表示颜色对象
/
public void mousepress(MouseEvent e, BufferedImage to,Color c) {
// TODO Auto-generated method stub
int[] dx={0,1,0,-1}; //水平偏移
int[] dy={1,0,-1,0}; //竖直偏移
int lim_x=togetWidth(),lim_y=togetHeight(); //获得的宽度和高度。
LinkedList<node> q=new LinkedList<node>(); //节点类型为node的链表
node a=new node(); //node应该有一个参数x表示水平坐标,y表示竖直坐标
node b;
ax=egetX();
ay=egetY(); //获得鼠标的水平与竖直坐标
int initrgb=togetRGB(ax, ay); //initrgb表示图像在水平坐标为x,竖直坐标为y处的灰度值。
int drawrgb=cgetRGB(); //颜色c对应的RGB值
if(initrgb==drawrgb) return; //如果此处颜色一致,直接返回
tosetRGB(ax, ay, drawrgb); //直接填充颜色
qaddLast(a); //将a加入到链表q中去
while(!qisEmpty()) //链表是否为空
{
a=qpollFirst(); //d出链表首位的node
for(int i=0;i<4;i++) //表示填充坐标(x,y)上、下、左、右的颜色,填充时对应的偏移量分别为dx[i],dy[i]
{
b=new node();
bx=ax+dx[i];
by=ay+dy[i];
if(bx<0 || by<0 || bx>=lim_x || by>=lim_y) continue;
if(togetRGB(bx, by)!=initrgb) continue;
tosetRGB(bx, by, drawrgb);
qaddLast(b); //将b加入链表中,
}
}
}
以上就是关于java中怎么样获取显示器宽度和高度的代码方法的代码import后面用那个包全部的内容,包括:java中怎么样获取显示器宽度和高度的代码方法的代码import后面用那个包、【紧急求助!!】java 获取图像宽度始终为-1,请教高手!!、请java高手注释一下这段程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)