<<think in java>>快要看完了,突然想写一个斗地主的游戏,前期基本的类都写好了,现在在界面这一块遇到一点问题,
扑克牌要用图片展示出来,我不想弄成一张扑克牌一张图片,现在所有的扑克牌都在一张图片里面,想用程序读进去,然后分割出来,我简略看了下其他的游戏,好像都是这么实现的,
可是我在swing和awt里面没有找到怎么分割,网上也不好搜索,特此请教各位牛人,有做过类似的给俺指点下,最好能有代码,3q

解决方案 »

  1.   

    参见java.awt.image.BufferedImage
    getSubimage
    public BufferedImage getSubimage(int x,
                                     int y,
                                     int w,
                                     int h)返回由指定矩形区域定义的子图像。返回的 BufferedImage 与源图像共享相同的数据数组。 
      

  2.   

    1楼能说的 具体点吗
    我查看BufferedImage的api
    没怎么明白,怎么构造这样一个对象,又怎么显示呢
      

  3.   

    import java.io.File;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;public class Test
    {
    File picFile = new File("path");
    BufferedImage bi;

    public Test()
    {
    try
    {
    bi = ImageIO.read(picFile);
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }

    public BufferedImage getChildImage(int x, int y, int w, int h)
    {
    return bi.getSubimage(x, y, w, h);
    }
    }
      

  4.   


    通过ImageIO从文件之类输入流读进来
      

  5.   

    BufferedImage bi = BufferedImage.read(new File("你的图片文件的地址"));
      

  6.   

    不好意思 哥们手抽 写错了 
    BufferedImage bi = ImageIO.read(new File("你的图片文件的地址"));