Feeling

              三人行,必有我師焉

             ::  :: 新隨筆 :: 聯系 ::  :: 管理 ::
            185 隨筆 :: 0 文章 :: 392 評論 :: 0 Trackbacks
          關于PaletteData的生成:
          case Gdip.PixelFormat16bppARGB1555:                                        
          case Gdip.PixelFormat16bppRGB555: 
              paletteData = new PaletteData(0x7C00, 0x3E0, 0x1F); 
          break;
          case Gdip.PixelFormat16bppRGB565: 
              paletteData = new PaletteData(0xF800, 0x7E0, 0x1F); 
          break;
          case Gdip.PixelFormat24bppRGB: 
              paletteData = new PaletteData(0xFF, 0xFF00, 0xFF0000); 
          break;
          case Gdip.PixelFormat32bppRGB:
          case Gdip.PixelFormat32bppARGB: 
              paletteData = new PaletteData(0xFF00, 0xFF0000, 0xFF000000); 
          break;

          32位ImageData中的data是以RGBA的順序存儲的。data[0]:red,data[1]:green,data[2]:blue,data[3]:alpha

          從byte[]中讀取RGB pixel:
          public static int getPixelFromRGBA( int depth, byte[] data )
          {
                  switch ( depth )
                  {
                      case 32 :
                          return ( ( data[0] & 0xFF ) << 24 )
                                  + ( ( data[1] & 0xFF ) << 16 )
                                  + ( ( data[2] & 0xFF ) << 8 )
                                  + ( data[3] & 0xFF );
                      case 24 :
                          return ( ( data[0] & 0xFF ) << 16 )
                                  + ( ( data[1] & 0xFF ) << 8 )
                                  + ( data[2] & 0xFF );
                      case 16 :
                          return ( ( data[1] & 0xFF ) << 8 ) + ( data[0] & 0xFF );
                      case 8 :
                          return data[0] & 0xFF;
                  }
                  SWT.error( SWT.ERROR_UNSUPPORTED_DEPTH );
                  return 0;
          }

          從pixel中取出RGB值:
          RGB rgb = imagedata.palette.getRGB( pixel );

          生成一個空的32位圖片:
          ImageData dest = new ImageData( width,
                          height,
                          32,
                          new PaletteData( 0xFF00, 0xFF0000, 0xFF000000 ) );

          24位透明圖片轉成32位透明圖片:
              public static ImageData convertToRGBA( ImageData src )
              {
                  ImageData dest = new ImageData( src.width,
                          src.height,
                          32,
                          new PaletteData( 0xFF00, 0xFF0000, 0xFF000000 ) );

                  for ( int x = 0; x < src.width; x++ )
                  {
                      for ( int y = 0; y < src.height; y++ )
                      {
                          int pixel = src.getPixel( x, y );
                          RGB rgb = src.palette.getRGB( pixel );

                          byte[] rgba = new byte[4];

                          rgba[0] = (byte) rgb.red;
                          rgba[1] = (byte) rgb.green;
                          rgba[2] = (byte) rgb.blue;

                          if ( pixel == src.transparentPixel )
                          {
                              rgba[3] = (byte) ( 0 );
                          }
                          else
                          {
                              rgba[3] = (byte) ( 255 );
                          }
                          dest.setPixel( x, y, getPixelFromRGBA( 32, rgba ) );
                      }
                  }
                  return dest;
              }

          posted on 2012-01-15 13:49 三人行,必有我師焉 閱讀(3569) 評論(1)  編輯  收藏

          評論

          # re: SWT ImageData的一些小結[未登錄] 2013-03-16 20:51
          用 SWT 怎么創建一個 空的 透明的圖片?  回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          GitHub |  開源中國社區 |  maven倉庫 |  文件格式轉換 
          主站蜘蛛池模板: 井陉县| 尚义县| 建昌县| 利辛县| 宁蒗| 本溪| 芜湖市| 慈利县| 花莲市| 平泉县| 萍乡市| 闽清县| 海阳市| 诏安县| 高要市| 寿光市| 上饶市| 嫩江县| 新绛县| 元江| 皮山县| 梅州市| 溆浦县| 东台市| 元氏县| 治县。| 乐亭县| 宜章县| 高阳县| 南康市| 新疆| 墨脱县| 章丘市| 盐源县| 察哈| 天长市| 齐河县| 呈贡县| 芷江| 静宁县| 左贡县|