郑希怡被拉掉裤子视频:java BMP

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 13:10:39
Java代码  
  1. /**  
  2.    loadbitmap() method converted from Windows C code.  
  3.    Reads only uncompressed 24- and 8-bit images.  Tested with  
  4.    images saved using Microsoft Paint in Windows 95.  If the image  
  5.    is not a 24- or 8-bit image, the program refuses to even try.  
  6.    I guess one could include 4-bit images by masking the byte  
  7.    by first 1100 and then 0011.  I am not really   
  8.    interested in such images.  If a compressed image is attempted,  
  9.    the routine will probably fail by generating an IOException.  
  10.    Look for variable ncompression to be different from 0 to indicate  
  11.    compression is present.  
  12.    Arguments:  
  13.        sdir and sfile are the result of the FileDialog()  
  14.        getDirectory() and getFile() methods.  
  15.    Returns:  
  16.        Image Object, be sure to check for (Image)null !!!!  
  17.    */  
  18.    public Image loadbitmap (String sdir, String sfile)   
  19.    {   
  20.    Image image;   
  21.    System.out.println("loading:"+sdir+sfile);   
  22.    try  
  23.        {   
  24.        FileInputStream fs=new FileInputStream(sdir+sfile);   
  25.        int bflen=14;  // 14 byte BITMAPFILEHEADER   
  26.        byte bf[]=new byte[bflen];   
  27.        fs.read(bf,0,bflen);   
  28.        int bilen=40; // 40-byte BITMAPINFOHEADER   
  29.        byte bi[]=new byte[bilen];   
  30.        fs.read(bi,0,bilen);   
  31.        // Interperet data.   
  32.        int nsize = (((int)bf[5]&0xff)<<24)    
  33.        | (((int)bf[4]&0xff)<<16)   
  34.        | (((int)bf[3]&0xff)<<8)   
  35.        | (int)bf[2]&0xff;   
  36.        System.out.println("File type is :"+(char)bf[0]+(char)bf[1]);   
  37.        System.out.println("Size of file is :"+nsize);   
  38.        int nbisize = (((int)bi[3]&0xff)<<24)   
  39.        | (((int)bi[2]&0xff)<<16)   
  40.        | (((int)bi[1]&0xff)<<8)   
  41.        | (int)bi[0]&0xff;   
  42.        System.out.println("Size of bitmapinfoheader is :"+nbisize);   
  43.        int nwidth = (((int)bi[7]&0xff)<<24)   
  44.        | (((int)bi[6]&0xff)<<16)   
  45.        | (((int)bi[5]&0xff)<<8)   
  46.        | (int)bi[4]&0xff;   
  47.        System.out.println("Width is :"+nwidth);   
  48.        int nheight = (((int)bi[11]&0xff)<<24)   
  49.        | (((int)bi[10]&0xff)<<16)   
  50.        | (((int)bi[9]&0xff)<<8)   
  51.        | (int)bi[8]&0xff;   
  52.        System.out.println("Height is :"+nheight);   
  53.        int nplanes = (((int)bi[13]&0xff)<<8) | (int)bi[12]&0xff;   
  54.        System.out.println("Planes is :"+nplanes);   
  55.        int nbitcount = (((int)bi[15]&0xff)<<8) | (int)bi[14]&0xff;   
  56.        System.out.println("BitCount is :"+nbitcount);   
  57.        // Look for non-zero values to indicate compression   
  58.        int ncompression = (((int)bi[19])<<24)   
  59.        | (((int)bi[18])<<16)   
  60.        | (((int)bi[17])<<8)   
  61.        | (int)bi[16];   
  62.        System.out.println("Compression is :"+ncompression);   
  63.        int nsizeimage = (((int)bi[23]&0xff)<<24)   
  64.        | (((int)bi[22]&0xff)<<16)   
  65.        | (((int)bi[21]&0xff)<<8)   
  66.        | (int)bi[20]&0xff;   
  67.        System.out.println("SizeImage is :"+nsizeimage);   
  68.        int nxpm = (((int)bi[27]&0xff)<<24)   
  69.        | (((int)bi[26]&0xff)<<16)   
  70.        | (((int)bi[25]&0xff)<<8)   
  71.        | (int)bi[24]&0xff;   
  72.        System.out.println("X-Pixels per meter is :"+nxpm);   
  73.        int nypm = (((int)bi[31]&0xff)<<24)   
  74.        | (((int)bi[30]&0xff)<<16)   
  75.        | (((int)bi[29]&0xff)<<8)   
  76.        | (int)bi[28]&0xff;   
  77.        System.out.println("Y-Pixels per meter is :"+nypm);   
  78.        int nclrused = (((int)bi[35]&0xff)<<24)   
  79.        | (((int)bi[34]&0xff)<<16)   
  80.        | (((int)bi[33]&0xff)<<8)   
  81.        | (int)bi[32]&0xff;   
  82.        System.out.println("Colors used are :"+nclrused);   
  83.        int nclrimp = (((int)bi[39]&0xff)<<24)   
  84.        | (((int)bi[38]&0xff)<<16)   
  85.        | (((int)bi[37]&0xff)<<8)   
  86.        | (int)bi[36]&0xff;   
  87.        System.out.println("Colors important are :"+nclrimp);   
  88.        if (nbitcount==24)   
  89.        {   
  90.        // No Palatte data for 24-bit format but scan lines are   
  91.        // padded out to even 4-byte boundaries.   
  92.        int npad = (nsizeimage / nheight) - nwidth * 3;   
  93.        int ndata[] = new int [nheight * nwidth];   
  94.        byte brgb[] = new byte [( nwidth + npad) * 3 * nheight];   
  95.        fs.read (brgb, 0, (nwidth + npad) * 3 * nheight);   
  96.        int nindex = 0;   
  97.        for (int j = 0; j < nheight; j++)   
  98.            {   
  99.            for (int i = 0; i < nwidth; i++)   
  100.            {   
  101.            ndata [nwidth * (nheight - j - 1) + i] =   
  102.                (255&0xff)<<24  
  103.                | (((int)brgb[nindex+2]&0xff)<<16)   
  104.                | (((int)brgb[nindex+1]&0xff)<<8)   
  105.                | (int)brgb[nindex]&0xff;   
  106.            // System.out.println("Encoded Color at ("   
  107.                +i+","+j+")is:"+nrgb+" (R,G,B)= ("  
  108.                +((int)(brgb[2]) & 0xff)+","  
  109.                +((int)brgb[1]&0xff)+","  
  110.                +((int)brgb[0]&0xff)+")");   
  111.            nindex += 3;   
  112.            }   
  113.            nindex += npad;   
  114.            }   
  115.        image = createImage   
  116.            ( new MemoryImageSource (nwidth, nheight,   
  117.                         ndata, 0, nwidth));   
  118.        }   
  119.        else if (nbitcount == 8)   
  120.        {   
  121.        // Have to determine the number of colors, the clrsused   
  122.        // parameter is dominant if it is greater than zero.  If   
  123.        // zero, calculate colors based on bitsperpixel.   
  124.        int nNumColors = 0;   
  125.        if (nclrused > 0)   
  126.            {   
  127.            nNumColors = nclrused;   
  128.            }   
  129.        else  
  130.            {   
  131.            nNumColors = (1&0xff)<
  132.            }   
  133.        System.out.println("The number of Colors is"+nNumColors);   
  134.        // Some bitmaps do not have the sizeimage field calculated   
  135.        // Ferret out these cases and fix 'em.   
  136.        if (nsizeimage == 0)   
  137.            {   
  138.            nsizeimage = ((((nwidth*nbitcount)+31) & 31 ) >> 3);   
  139.            nsizeimage *= nheight;   
  140.            System.out.println("nsizeimage (backup) is"+nsizeimage);   
  141.            }   
  142.        // Read the palatte colors.   
  143.        int  npalette[] = new int [nNumColors];   
  144.        byte bpalette[] = new byte [nNumColors*4];   
  145.        fs.read (bpalette, 0, nNumColors*4);   
  146.        int nindex8 = 0;   
  147.        for (int n = 0; n < nNumColors; n++)   
  148.            {   
  149.            npalette[n] = (255&0xff)<<24  
  150.            | (((int)bpalette[nindex8+2]&0xff)<<16)   
  151.            | (((int)bpalette[nindex8+1]&0xff)<<8)   
  152.            | (int)bpalette[nindex8]&0xff;   
  153.            // System.out.println ("Palette Color "+n   
  154.            +" is:"+npalette[n]+" (res,R,G,B)= ("  
  155.            +((int)(bpalette[nindex8+3]) & 0xff)+","  
  156.            +((int)(bpalette[nindex8+2]) & 0xff)+","  
  157.            +((int)bpalette[nindex8+1]&0xff)+","  
  158.            +((int)bpalette[nindex8]&0xff)+")");   
  159.            nindex8 += 4;   
  160.            }   
  161.        // Read the image data (actually indices into the palette)   
  162.        // Scan lines are still padded out to even 4-byte   
  163.        // boundaries.   
  164.        int npad8 = (nsizeimage / nheight) - nwidth;   
  165.        System.out.println("nPad is:"+npad8);   
  166.        int  ndata8[] = new int [nwidth*nheight];   
  167.        byte bdata[] = new byte [(nwidth+npad8)*nheight];   
  168.        fs.read (bdata, 0, (nwidth+npad8)*nheight);   
  169.        nindex8 = 0;   
  170.        for (int j8 = 0; j8 < nheight; j8++)   
  171.            {   
  172.            for (int i8 = 0; i8 < nwidth; i8++)   
  173.            {   
  174.            ndata8 [nwidth*(nheight-j8-1)+i8] =   
  175.                npalette [((int)bdata[nindex8]&0xff)];   
  176.            nindex8++;   
  177.            }   
  178.            nindex8 += npad8;   
  179.            }   
  180.        image = createImage   
  181.            ( new MemoryImageSource (nwidth, nheight,   
  182.                         ndata8, 0, nwidth));   
  183.        }   
  184.        else  
  185.        {   
  186.        System.out.println ("Not a 24-bit or 8-bit Windows Bitmap, aborting...");   
  187.        image = (Image)null;   
  188.        }   
  189.        fs.close();   
  190.        return image;   
  191.        }   
  192.    catch (Exception e)   
  193.        {   
  194.        System.out.println("Caught exception in loadbitmap!");   
  195.        }   
  196.    return (Image) null;   
  197.    }