麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Delphi > 正文

Delphi常見圖象格式轉(zhuǎn)換技術(shù)(二)

2019-11-18 18:47:43
字體:
供稿:網(wǎng)友

Delphi常見圖象格式轉(zhuǎn)換技術(shù)(二)
作者:lyboy99
e-mail:[email protected]  
url: http://hnh.126.com

給大家提供幾個常用的圖象格式轉(zhuǎn)換方法和其轉(zhuǎn)換函數(shù)
希望可以對你有幫助

1.TxT 轉(zhuǎn)換為 GIF
2.WMF格式轉(zhuǎn)換為BMP格式
3.BMP格式轉(zhuǎn)換為WMF格式
4.TBitmaps to Windows Regions
-----------------------------------------------------------------------
TxT 轉(zhuǎn)換為 GIF
------------------------------------------------
PRocedure TxtToGif (txt, FileName: String);
var
    temp: TBitmap;
    GIF : TGIFImage;
begin

temp:=TBitmap.Create;
try
        temp.Height     :=400;
        temp.Width      :=60;
        temp.Transparent:=True;
        temp.Canvas.Brush.Color:=colFondo.ColorValue;
        temp.Canvas.Font.Name:=Fuente.FontName;
        temp.Canvas.Font.Color:=colFuente.ColorValue;
        temp.Canvas.TextOut (10,10,txt);
        Imagen.Picture.Assign(nil);

      GIF := TGIFImage.Create;
      try
       
        GIF.Assign(Temp);
        //保存 GIF
        GIF.SaveToFile(FileName);
        Imagen.Picture.Assign (GIF);
     finally
        GIF.Free;
      end;

Finally

        temp.Destroy;
End;
end;
---------------------------------------------------------------------
2.WMF格式轉(zhuǎn)換為BMP格式

--------------------------------------------------------------------
procedure WmfToBmp(FicheroWmf,FicheroBmp:string); 
var 
  MetaFile:TMetafile; 
  Bmp:TBitmap; 
begin 
  Metafile:=TMetaFile.create; 
  {Create a Temporal Bitmap} 
  Bmp:=TBitmap.create; 
  {Load the Metafile} 
  MetaFile.LoadFromFile(FicheroWmf); 
  {Draw the metafile in Bitmap's canvas} 
  with Bmp do 
  begin 
   Height:=Metafile.Height; 
   Width:=Metafile.Width; 
   Canvas.Draw(0,0,MetaFile); 
   {Save the BMP} 
   SaveToFile(FicheroBmp); 
   {Free BMP} 
   Free; 
  end; 
  {Free Metafile} 
  MetaFile.Free; 
end; 


---------------------------------------------------------------------
3.BMP格式轉(zhuǎn)換為WMF格式
---------------------------------------------------------------------
procedure BmpToWmf (BmpFile,WmfFile:string); 
var 
  MetaFile : TMetaFile; 
  MFCanvas : TMetaFileCanvas; 
  BMP : TBitmap; 
begin 
  {Create temps} 
  MetaFile := TMetaFile.Create; 
  BMP := TBitmap.create; 
  BMP.LoadFromFile(BmpFile); 
  {Igualemos tama?os} 
  {Equalizing sizes} 
  MetaFile.Height := BMP.Height; 
  MetaFile.Width := BMP.Width; 
  {Create a canvas for the Metafile} 
  MFCanvas:=TMetafileCanvas.Create(MetaFile, 0); 
  with MFCanvas do 
  begin 
  {Draw the BMP into canvas} 
  Draw(0, 0, BMP); 
  {Free the Canvas} 
  Free; 
  end; 
  {Free the BMP} 
  BMP.Free; 
  with MetaFile do 
  begin 
  {Save the Metafile} 
  SaveToFile(WmfFile); 
   {Free it...} 
  Free; 
  end; 
end;

---------------------------------------------------------------------

4.TBitmaps to Windows Regions
---------------------------------------------------------------------
function BitmapToRegion(bmp: TBitmap; TransparentColor: TColor=clBlack;
  RedTol: Byte=1; GreenTol: Byte=1; BlueTol: Byte=1): HRGN;
const
  AllocUnit = 100;
type
  PRectArray = ^TRectArray;
  TRectArray = Array[0..(MaxInt div SizeOf(TRect))-1] of TRect;
var
  pr: PRectArray;   
  h: HRGN;         
  RgnData: PRgnData;
  lr, lg, lb, hr, hg, hb: Byte;
  x,y, x0: Integer; 
  b: PByteArray;   
  ScanLinePtr: Pointer;
  ScanLineInc: Integer;
  maxRects: Cardinal;  
begin
  Result := 0;
  { Keep on hand lowest and highest values for the "transparent" pixels }
  lr := GetRValue(TransparentColor);
  lg := GetGValue(TransparentColor);
  lb := GetBValue(TransparentColor);
  hr := Min($ff, lr + RedTol);
  hg := Min($ff, lg + GreenTol);
  hb := Min($ff, lb + BlueTol);
 
  bmp.PixelFormat := pf32bit;
 
  maxRects := AllocUnit;
  GetMem(RgnData,SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * maxRects));
  try
    with RgnData^.rdh do
    begin
      dwSize := SizeOf(RGNDATAHEADER);
      iType := RDH_RECTANGLES;
      nCount := 0;
      nRgnSize := 0;
      SetRect(rcBound, MAXLONG, MAXLONG, 0, 0);
    end;
 
    ScanLinePtr := bmp.ScanLine[0];
    ScanLineInc := Integer(bmp.ScanLine[1]) - Integer(ScanLinePtr);
    for y := 0 to bmp.Height - 1 do
    begin
      x := 0;
      while x < bmp.Width do
      begin
        x0 := x;
        while x < bmp.Width do
        begin
          b := @PByteArray(ScanLinePtr)[x*SizeOf(TRGBQuad)];
          // BGR-RGB: Windows 32bpp BMPs are made of BGRa quads (not RGBa)
          if (b[2] >= lr) and (b[2] <= hr) and
             (b[1] >= lg) and (b[1] <= hg) and
             (b[0] >= lb) and (b[0] <= hb) then
            Break; // pixel is transparent
          Inc(x);
        end;
        { test to see if we have a non-transparent area in the image }
        if x > x0 then
        begin
          { increase RgnData by AllocUnit rects if we exceeds maxRects }
          if RgnData^.rdh.nCount >= maxRects then
          begin
            Inc(maxRects,AllocUnit);
            ReallocMem(RgnData,SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * MaxRects));
          end;
          { Add the rect (x0, y)-(x, y+1) as a new visible area in the region }
          pr := @RgnData^.Buffer; // Buffer is an array of rects
          with RgnData^.rdh do
          begin
            SetRect(pr[nCount], x0, y, x, y+1);
            { adjust the bound rectangle of the region if we are "out-of-bounds" }
            if x0 < rcBound.Left then rcBound.Left := x0;
            if y < rcBound.Top then rcBound.Top := y;
            if x > rcBound.Right then rcBound.Right := x;
            if y+1 > rcBound.Bottom then rcBound.Bottom := y+1;
            Inc(nCount);
          end;
        end; // if x > x0
      
       
        if RgnData^.rdh.nCount = 2000 then
        begin
          h := ExtCreateRegion(nil, SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * maxRects), RgnData^);
          if Result > 0 then
          begin // Expand the current region
            CombineRgn(Result, Result, h, RGN_OR);
            DeleteObject(h);
          end
          else  // First region, assign it to Result
            Result := h;
          RgnData^.rdh.nCount := 0;
          SetRect(RgnData^.rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
        end;
        Inc(x);
      end; // scan every sample byte of the image
      Inc(Integer(ScanLinePtr), ScanLineInc);
    end;
    { need to call ExCreateRegion one more time because we could have left    }
    { a RgnData with less than 2000 rects, so it wasn't yet created/combined  }
    h := ExtCreateRegion(nil, SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * MaxRects), RgnData^);
    if Result > 0 then
    begin
      CombineRgn(Result, Result, h, RGN_OR);
      DeleteObject(h);
    end
    else
      Result := h;
  finally
    FreeMem(RgnData,SizeOf(RGNDATAHEADER) + (SizeOf(TRect) * MaxRects));
  end;

----------------------------------------------------------------------------------


上一篇:Delphi下常用數(shù)學(xué)運算函數(shù)

下一篇:Delphi下常用轉(zhuǎn)換(一)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
學(xué)習(xí)交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網(wǎng)友關(guān)注

主站蜘蛛池模板: 久久精品首页 | 亚洲一级片免费观看 | 国产不卡av在线 | 久章草在线视频 | 久久久久久久久久久久免费 | 中文字幕在线观看精品 | 偷偷草网站 | 亚洲一级电影在线观看 | 国产一区二区三区精品在线观看 | 久久艹综合| 久久久一区二区三区精品 | 欧美极品欧美精品欧美视频 | 日本精品婷婷久久爽一下 | 日本看片一区二区三区高清 | 日本一区二区免费在线观看 | 日本黄色不卡视频 | 中文字幕一二三区芒果 | 欧美成a人片在线观看久 | 免费久久久 | 综合国产在线 | 九草在线 | 国产区二区 | 日本成人二区 | 成码无人av片在线观看网站 | 久久午夜国产 | 久久精品99久久久久久2456 | 黄色一级视频 | 精品国产一区二区三区免费 | 日韩午夜一区二区三区 | 九九精品影院 | 12av毛片 | 国产www免费| 精品国产一区二区三区在线 | 亚洲影院在线 | 青草av.久久免费一区 | 免费国产在线视频 | 最新av在线免费观看 | 369看片你懂的小视频在线观看 | 成人午夜视频免费在线观看 | 一区二区三区欧美在线 | 免费国产视频大全入口 |