Ads

Ads

Translate

Thursday, 1 November 2012

Membuat tumbnail pada Delphi

By Fajar  |  November 01, 2012 No comments


Saya ingin tanya nich, gimana caranya melakukan konversi dari bmp dari segala ukuran ( misalnya : 100 x 50 pixel atau 600 x 300 pixel ) ke bentuk mini (spt thumbnail) ? 

Jawaban
Caranya kelihatannya bisa bermacam-macam. Ini saya coba berikan salah
satu cara yang sederhana.


procedure CreateThumbnail(SrcBmp, DestBmp: TBitmap;
ProportionalResize: Boolean);
var
  PropWidth, PropHeight: Integer;
begin
  if ProportionalResize then
 begin
  // mencari ukuran TxL yang proporsional
  if SrcBmp.Width/DestBmp.Width < SrcBmp.Height/DestBmp.Height
  then
  begin
     PropWidth := SrcBmp.Width;
     
PropHeight := PropWidth * DestBmp.Height div      DestBmp.Width;
  end else
  begin
     PropHeight := SrcBmp.Height;
     
PropWidth := PropHeight * DestBmp.Width div DestBmp.Height;
  end;

 end else
 begin
     PropWidth := SrcBmp.Width;
     PropHeight := SrcBmp.Height;
end;

// dibawah ini kalau nggak mau ber-WinAPI, bisa pakai
// method TCanvas.StretchDraw(), tentunya dengan parameter
// yang berbeda

if not StretchBlt(DestBmp.Canvas.Handle, 0, 0,
DestBmp.Width, DestBmp.Height,
SrcBmp.Canvas.Handle, 0, 0, PropWidth, PropHeight,
SRCCOPY)
then
RaiseLastWin32Error;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  SrcBmp, DestBmp: TBitmap;
begin
  SrcBmp := TBitmap.Create;
  try
    SrcBmp.LoadFromFile('C:\BigSizeBitmap.bmp');
    DestBmp := TBitmap.Create;
    try
      // dimensi thumbnail
      DestBmp.Width := 16;
      DestBmp.Height := 16;
      CreateThumbnail(SrcBmp, DestBmp, True);
      // misalnya thumbnail dipakai sebagai glyph
      // pada TSpeedButton...
      SpeedButton1.Glyph.Assign(DestBmp);
    finally
      DestBmp.Free;
    end;
  finally
  SrcBmp.Free;
  end;
end;

Fajar Author: Fajar

Hello, I am Author, decode to know more: In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet.

Related Posts

0 comments:

Best Post This Year

Install Fortesreport community Delphi 7 dan RX Berlin

Download  Pertama2 kita harus punya file installernya terlebih dahulu, download  https://github.com/fortesinformatica/fortesrepo...

Total Pageviews

1,244,949
© 2014 Fajar Priyadi. WP themonic converted by Bloggertheme9. Published By Gooyaabi Templates | Powered By Blogger