⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cur.java

📁 java实现Animate鼠标,java 中不支持cur或ani的鼠标
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                   if (planes == 1 && bitCount == 1)
                       colorCount [i] = 2;
                   else
                   if (planes == 1 && bitCount == 4)
                       colorCount [i] = 16;
                   else
                   if (planes == 1 && bitCount == 8)
                       colorCount [i] = 256;
                   else
                   if (planes != 1 && bitCount != 32)
                       throw new BadCurResException ("invalid color count");
               }

               bi [i] = new BufferedImage (width, height,
                                           BufferedImage.TYPE_INT_ARGB);

               // Parse image to image buffer.

               int colorTableOffset = imageOffset+BMIH_LENGTH;

               if (colorCount [i] == 2)
               {
                   int xorImageOffset = colorTableOffset+2*4;

                   int scanlineBytes = calcScanlineBytes (width, 1);
                   int andImageOffset = xorImageOffset+scanlineBytes*height;

                   int [] masks = { 128, 64, 32, 16, 8, 4, 2, 1 };

                   for (int row = 0; row < height; row++)
                        for (int col = 0; col < width; col++)
                        {
                             int index;

                             if ((ubyte (curimage [xorImageOffset+row*
                                                   scanlineBytes+col/8])
                                 & masks [col%8]) != 0)
                                 index = 1;
                             else
                                 index = 0;

                             int rgb = 0;
                             rgb |= (ubyte (curimage [colorTableOffset+index*4
                                                      +2]));
                             rgb <<= 8;
                             rgb |= (ubyte (curimage [colorTableOffset+index*4
                                                      +1]));
                             rgb <<= 8;
                             rgb |= (ubyte (curimage [colorTableOffset+index*
                                                      4]));

                             if ((ubyte (curimage [andImageOffset+row*
                                                   scanlineBytes+col/8])
                                 & masks [col%8]) != 0)
                                 bi [i].setRGB (col, height-1-row, rgb);
                             else
                                 bi [i].setRGB (col, height-1-row,
                                                0xff000000 | rgb);
                        }
               }
               else
               if (colorCount [i] == 16)
               {
                   int xorImageOffset = colorTableOffset+16*4;

                   int scanlineBytes = calcScanlineBytes (width, 4);
                   int andImageOffset = xorImageOffset+scanlineBytes*height;

                   int [] masks = { 128, 64, 32, 16, 8, 4, 2, 1 };

                   for (int row = 0; row < height; row++)
                        for (int col = 0; col < width; col++)
                        {
                             int index;
                             if ((col & 1) == 0) // even
                             {
                                 index = ubyte (curimage [xorImageOffset+row*
                                                          scanlineBytes+col/2]);
                                 index >>= 4;
                             }
                             else
                             {
                                 index = ubyte (curimage [xorImageOffset+row*
                                                          scanlineBytes+col/2])
                                                &15;
                             }

                             int rgb = 0;
                             rgb |= (ubyte (curimage [colorTableOffset+index*4
                                                      +2]));
                             rgb <<= 8;
                             rgb |= (ubyte (curimage [colorTableOffset+index*4
                                                      +1]));
                             rgb <<= 8;
                             rgb |= (ubyte (curimage [colorTableOffset+index*
                                                      4]));

                             if ((ubyte (curimage [andImageOffset+row*
                                                   calcScanlineBytes (width, 1)
                                                   +col/8]) & masks [col%8])
                                 != 0)
                                 bi [i].setRGB (col, height-1-row, rgb);
                             else
                                 bi [i].setRGB (col, height-1-row,
                                                0xff000000 | rgb);
                        }
               }
               else
               if (colorCount [i] == 256)
               {
                   int xorImageOffset = colorTableOffset+256*4;

                   int scanlineBytes = calcScanlineBytes (width, 8);
                   int andImageOffset = xorImageOffset+scanlineBytes*height;

                   int [] masks = { 128, 64, 32, 16, 8, 4, 2, 1 };

                   for (int row = 0; row < height; row++)
                        for (int col = 0; col < width; col++)
                        {
                             int index;
                             index = ubyte (curimage [xorImageOffset+row*
                                                      scanlineBytes+col]);

                             int rgb = 0;
                             rgb |= (ubyte (curimage [colorTableOffset+index*4
                                                      +2]));
                             rgb <<= 8;
                             rgb |= (ubyte (curimage [colorTableOffset+index*4
                                                      +1]));
                             rgb <<= 8;
                             rgb |= (ubyte (curimage [colorTableOffset+index*4
                                                      ]));

                             if ((ubyte (curimage [andImageOffset+row*
                                                   calcScanlineBytes (width, 1)
                                                   +col/8]) & masks [col%8])
                                 != 0)
                                 bi [i].setRGB (col, height-1-row, rgb);
                             else
                                 bi [i].setRGB (col, height-1-row,
                                                0xff000000 | rgb);
                        }
               }
               else
               if (colorCount [i] == 0)
               {
                   int scanlineBytes = calcScanlineBytes (width, 32);

                   for (int row = 0; row < height; row++)
                        for (int col = 0; col < width; col++)
                        {
                             int rgb = ubyte (curimage [colorTableOffset+row*
                                                        scanlineBytes+col*4+3]);
                             rgb <<= 8;
                             rgb |= ubyte (curimage [colorTableOffset+row*
                                                     scanlineBytes+col*4+2]);
                             rgb <<= 8;
                             rgb |= ubyte (curimage [colorTableOffset+row*
                                                     scanlineBytes+col*4+1]);
                             rgb <<= 8;
                             rgb |= ubyte (curimage [colorTableOffset+row*
                                                     scanlineBytes+col*4]);

                             bi [i].setRGB (col, height-1-row, rgb);
                        }
               }
           }
           else
           if (ubyte (curimage [imageOffset]) == 0x89 &&
               curimage [imageOffset+1] == 0x50 &&
               curimage [imageOffset+2] == 0x4e &&
               curimage [imageOffset+3] == 0x47 &&
               curimage [imageOffset+4] == 0x0d &&
               curimage [imageOffset+5] == 0x0a &&
               curimage [imageOffset+6] == 0x1a &&
               curimage [imageOffset+7] == 0x0a)
           {
               // PNG detected

               ByteArrayInputStream bais;
               bais = new ByteArrayInputStream (curimage, imageOffset,
                                                bytesInRes); 
               bi [i] = ImageIO.read (bais);
           }
           else
               throw new BadCurResException ("BITMAPINFOHEADER or PNG "+
                                             "expected");
      }

      curimage = null; // This array can now be garbage collected.
   }

   private void read (InputStream is) throws IOException
   {
      int bytesToRead;
      while ((bytesToRead = is.available ()) != 0)
      {
         byte [] curimage2 = new byte [curimage.length+bytesToRead];
         System.arraycopy (curimage, 0, curimage2, 0, curimage.length);
         is.read (curimage2, curimage.length, bytesToRead);         
         curimage = curimage2;
      }
   }

   private int ubyte (byte b)
   {
      return (b < 0) ? 256+b : b; // Convert byte to unsigned byte.
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -