程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> GDI+ 學習記錄(27): Bitmap

GDI+ 學習記錄(27): Bitmap

編輯:Delphi

//用 Bitmap 顯示圖像

var
 g: TGPGraphics;
 bit: TGPBitmap;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 bit := TGPBitmap.Create('c:tempx.jpg');
 g.DrawImage(bit, 11, 11); {默認大小竟然和 1:1 不一樣, 是不是分辨率的問題?}
 g.DrawImage(bit, 11, 11, bit.GetWidth, bit.GetHeight);     {1:1}
 g.DrawImage(bit, 11, 11, bit.GetWidth*0.5, bit.GetHeight*0.5); {1:2}
 bit.Free;
 g.Free;
end;

  //復制像素

var
 g: TGPGraphics;
 bit1,bit2: TGPBitmap;
 row,column,width,height: Integer;
 color: TGPColor;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 bit1 := TGPBitmap.Create('c:tempx.jpg');
 width := bit1.GetWidth;
 height := bit1.GetHeight;
 bit2 := TGPBitmap.Create(width, height);
 for row := 0 to height - 1 do
 begin
  for column := 0 to width - 1 do
  begin
   bit1.GetPixel(column, row, color);
   bit2.SetPixel(column, row, color);
  end;
 end;
 g.DrawImage(bit1, 0, 0, width, height);
 g.DrawImage(bit2, width, 0, width, height);
 bit1.Free;
 bit2.Free;
 g.Free;
end;

  //橫向翻轉

var
 g: TGPGraphics;
 bit1,bit2: TGPBitmap;
 row,column,width,height: Integer;
 color: TGPColor;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 bit1 := TGPBitmap.Create('c:tempx.jpg');
 width := bit1.GetWidth;
 height := bit1.GetHeight;
 bit2 := TGPBitmap.Create(width, height);
 for row := 0 to height - 1 do
 begin
  for column := 0 to width - 1 do
  begin
   bit1.GetPixel(column, row, color);
   bit2.SetPixel(width-column, row, color); {width-column}
  end;
 end;
 g.DrawImage(bit1, 0, 0, width, height);
 g.DrawImage(bit2, width, 0, width, height);
 bit1.Free;
 bit2.Free;
 g.Free;
end;

  //縱向翻轉

var
 g: TGPGraphics;
 bit1,bit2: TGPBitmap;
 row,column,width,height: Integer;
 color: TGPColor;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 bit1 := TGPBitmap.Create('c:tempx.jpg');
 width := bit1.GetWidth;
 height := bit1.GetHeight;
 bit2 := TGPBitmap.Create(width, height);
 for row := 0 to height - 1 do
 begin
  for column := 0 to width - 1 do
  begin
   bit1.GetPixel(column, row, color);
   bit2.SetPixel(column, height-row, color); {height-row}
  end;
 end;
 g.DrawImage(bit1, 0, 0, width, height);
 g.DrawImage(bit2, width, 0, width, height);
 bit1.Free;
 bit2.Free;
 g.Free;
end;

  //透明度漸變

var
 g: TGPGraphics;
 bit1,bit2: TGPBitmap;
 row,column,width,height: Integer;
 color: TGPColor;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 bit1 := TGPBitmap.Create('c:tempx.jpg');
 width := bit1.GetWidth;
 height := bit1.GetHeight;
 bit2 := TGPBitmap.Create(width, height);
 for row := 0 to height - 1 do
 begin
  for column := 0 to width - 1 do
  begin
   bit1.GetPixel(column, row, color);
   color := MakeColor(255 * Column div width,
             GetRed(color),
             GetGreen(color),
             GetBlue(color));
   bit2.SetPixel(column, row, color);
  end;
 end;
 g.DrawImage(bit1, 0, 0, width, height);
 g.DrawImage(bit2, width, 0, width, height);
 bit1.Free;
 bit2.Free;
 g.Free;
end;

  //顯示 ico 圖標

var
 g : TGPGraphics;
 bit: TGPBitmap;
 ico: HICON;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 ico := LoadIcon(0, IDI_QUESTION);
 bit:= TGPBitmap.Create(ico);
 g.DrawImage(bit, 10, 10);
 bit.Free;
 g.Free;
end;


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved