import
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
program ImagePreview;
|
||||
|
||||
uses
|
||||
Forms,
|
||||
MainFrm in 'MainFrm.pas' {MainForm};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TMainForm, MainForm);
|
||||
Application.Run;
|
||||
end.
|
||||
Binary file not shown.
@@ -0,0 +1,135 @@
|
||||
object MainForm: TMainForm
|
||||
Left = 304
|
||||
Top = 165
|
||||
Width = 467
|
||||
Height = 405
|
||||
Caption = 'Image Preview'
|
||||
Color = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
KeyPreview = True
|
||||
OldCreateOrder = False
|
||||
Position = poDesktopCenter
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnKeyUp = FormKeyUp
|
||||
OnMouseWheel = ScrollBoxMouseWheel
|
||||
OnShow = FormShow
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object ImgView32: TImgView32
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 459
|
||||
Height = 371
|
||||
Align = alClient
|
||||
ParentShowHint = False
|
||||
PopupMenu = PopupMenu
|
||||
Scale = 1
|
||||
ScrollBars.Color = clScrollBar
|
||||
ScrollBars.ShowHandleGrip = True
|
||||
ScrollBars.Style = rbsDefault
|
||||
ShowHint = True
|
||||
SizeGrip = sgAuto
|
||||
TabOrder = 0
|
||||
OnScroll = ImgView32Scroll
|
||||
object AlphaView: TImgView32
|
||||
Left = 8
|
||||
Top = 8
|
||||
Width = 161
|
||||
Height = 145
|
||||
Scale = 1
|
||||
ScrollBars.Color = clScrollBar
|
||||
ScrollBars.ShowHandleGrip = True
|
||||
ScrollBars.Style = rbsDefault
|
||||
SizeGrip = sgAuto
|
||||
TabOrder = 2
|
||||
Visible = False
|
||||
end
|
||||
end
|
||||
object PopupMenu: TPopupMenu
|
||||
Left = 304
|
||||
Top = 28
|
||||
object ZoomInItem: TMenuItem
|
||||
Caption = 'Zoom In'
|
||||
OnClick = ZoomInItemClick
|
||||
end
|
||||
object ZoomOutItem: TMenuItem
|
||||
Caption = 'Zoom Out'
|
||||
OnClick = ZoomOutItemClick
|
||||
end
|
||||
object ActualSizeItem: TMenuItem
|
||||
Caption = 'Actual Size'
|
||||
OnClick = ActualSizeItemClick
|
||||
end
|
||||
object N1: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object RotateClockwiseItem: TMenuItem
|
||||
Caption = 'Rotate Clockwise'
|
||||
OnClick = RotateClockwiseItemClick
|
||||
end
|
||||
object RotateAntiClockwiseItem: TMenuItem
|
||||
Caption = 'Rotate Anti-Clockwise'
|
||||
OnClick = RotateAntiClockwiseItemClick
|
||||
end
|
||||
object N4: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object FlipHorizontalItem: TMenuItem
|
||||
Caption = 'Flip Horizontal'
|
||||
OnClick = FlipHorizontalItemClick
|
||||
end
|
||||
object FilpVerticalItem: TMenuItem
|
||||
Caption = 'Filp Vertical'
|
||||
OnClick = FilpVerticalItemClick
|
||||
end
|
||||
object N3: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object ShowAlphaItem: TMenuItem
|
||||
Caption = 'Show Just Alpha Channel'
|
||||
OnClick = ShowAlphaItemClick
|
||||
end
|
||||
object ShowWithAlphaItem: TMenuItem
|
||||
Caption = 'Show With Alpha Channel'
|
||||
OnClick = ShowWithAlphaItemClick
|
||||
end
|
||||
object N2: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object OpenImageItem: TMenuItem
|
||||
Caption = 'Open New Image'
|
||||
OnClick = OpenImageItemClick
|
||||
end
|
||||
end
|
||||
object FilterTimer: TTimer
|
||||
Interval = 500
|
||||
OnTimer = FilterTimerTimer
|
||||
Left = 308
|
||||
Top = 84
|
||||
end
|
||||
object OpenDialog: TOpenDialog
|
||||
Filter =
|
||||
'All image files|*.bmp;*.cut;*.ico;*.iff;*.lbm;*.jng;*.jpg;*.jpeg' +
|
||||
';*.koa;*.mng;*.pbm;*.pcd;*.pcx;*.pgm;*.png;*.ppm;*.psd;*.ras;*.t' +
|
||||
'ga;*.tif;*.tiff;.wbmp;*.xbm;*.xpm)|Windows or OS/2 Bitmap File (' +
|
||||
'*.BMP)|*.BMP|Dr. Halo (*.CUT)|*.CUT|Windows Icon (*.ICO)|*.ICO|A' +
|
||||
'miga IFF (*.IFF, *.LBM)|*.IFF;*.LBM|JPEG Network Graphics (*.JNG' +
|
||||
')|*.JNG|Independent JPEG Group (*.JPG)|*.JPG|Commodore 64 Koala ' +
|
||||
'(*.KOA)|*.KOA|Multiple Network Graphics (*.MNG)|*.MNG|Portable B' +
|
||||
'itmap (*.PBM)|*.PBM|Kodak PhotoCD (*.PCD)|*.PCD|PCX bitmap forma' +
|
||||
't (*.PCX)|*.PCX|Portable Graymap (*.PGM)|*.PGM|Portable Network ' +
|
||||
'Graphics (*.PNG)|*.PNG|Portable Pixelmap (*.PPM)|*.PPM|Photoshop' +
|
||||
' (*.PSD)|*.PSD|Sun Rasterfile (*.RAS)|*.RAS|Targa files (*.TGA)|' +
|
||||
'*.TGA|Tagged Image File Format (*.TIF)|*.TIF;*.TIFF|Wireless Bit' +
|
||||
'map (*.WBMP)|*.WBMP|X11 Bitmap Format (*.XBM)|*.XBM|X11 Pixmap F' +
|
||||
'ormat (*.XPM)|*.XPM'
|
||||
Title = 'Open Image File'
|
||||
Left = 328
|
||||
Top = 228
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,518 @@
|
||||
unit MainFrm;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, Menus, ExtCtrls, Math, GR32, GR32_Image, GR32_Transforms,
|
||||
ExtDlgs;
|
||||
|
||||
type
|
||||
TMainForm = class(TForm)
|
||||
PopupMenu: TPopupMenu;
|
||||
ZoomInItem: TMenuItem;
|
||||
ZoomOutItem: TMenuItem;
|
||||
ActualSizeItem: TMenuItem;
|
||||
ImgView32: TImgView32;
|
||||
N1: TMenuItem;
|
||||
AlphaView: TImgView32;
|
||||
ShowAlphaItem: TMenuItem;
|
||||
RotateClockwiseItem: TMenuItem;
|
||||
RotateAntiClockwiseItem: TMenuItem;
|
||||
N3: TMenuItem;
|
||||
ShowWithAlphaItem: TMenuItem;
|
||||
N4: TMenuItem;
|
||||
FlipHorizontalItem: TMenuItem;
|
||||
FilpVerticalItem: TMenuItem;
|
||||
FilterTimer: TTimer;
|
||||
OpenImageItem: TMenuItem;
|
||||
N2: TMenuItem;
|
||||
OpenDialog: TOpenDialog;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure ZoomInItemClick(Sender: TObject);
|
||||
procedure ZoomOutItemClick(Sender: TObject);
|
||||
procedure ActualSizeItemClick(Sender: TObject);
|
||||
procedure ScrollBoxMouseWheel(Sender: TObject; Shift: TShiftState;
|
||||
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
||||
procedure FormKeyUp(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
procedure ShowAlphaItemClick(Sender: TObject);
|
||||
procedure RotateClockwiseItemClick(Sender: TObject);
|
||||
procedure RotateAntiClockwiseItemClick(Sender: TObject);
|
||||
procedure ShowWithAlphaItemClick(Sender: TObject);
|
||||
procedure FlipHorizontalItemClick(Sender: TObject);
|
||||
procedure FilpVerticalItemClick(Sender: TObject);
|
||||
procedure FilterTimerTimer(Sender: TObject);
|
||||
procedure ImgView32Scroll(Sender: TObject);
|
||||
procedure OpenImageItemClick(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
OrigWidth : integer;
|
||||
OrigHeight : integer;
|
||||
BPP : longword;
|
||||
|
||||
procedure LoadImage( Name : string);
|
||||
procedure RecalcWindowSize;
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
MainForm: TMainForm;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
uses FreeImage;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
AlphaView.Visible := False;
|
||||
AlphaView.Align := alClient;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
// ...
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.FormShow(Sender: TObject);
|
||||
begin
|
||||
ImgView32.Bitmap.StretchFilter := sfSPline;
|
||||
if ParamCount = 1 then
|
||||
LoadImage(ParamStr(1));
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.LoadImage( Name : string);
|
||||
var
|
||||
dib : PFIBITMAP;
|
||||
PBH : PBITMAPINFOHEADER;
|
||||
PBI : PBITMAPINFO;
|
||||
t : FREE_IMAGE_FORMAT;
|
||||
Ext : string;
|
||||
BM : TBitmap;
|
||||
x, y : integer;
|
||||
BP : PLONGWORD;
|
||||
DC : HDC;
|
||||
begin
|
||||
try
|
||||
t := FreeImage_GetFileType(PChar(Name), 16);
|
||||
|
||||
if t = FIF_UNKNOWN then
|
||||
begin
|
||||
// Check for types not supported by GetFileType
|
||||
Ext := UpperCase(ExtractFileExt(Name));
|
||||
if (Ext = '.TGA') or(Ext = '.TARGA') then
|
||||
t := FIF_TARGA
|
||||
else if Ext = '.MNG' then
|
||||
t := FIF_MNG
|
||||
else if Ext = '.PCD' then
|
||||
t := FIF_PCD
|
||||
else if Ext = '.WBMP' then
|
||||
t := FIF_WBMP
|
||||
else if Ext = '.CUT' then
|
||||
t := FIF_CUT
|
||||
else
|
||||
raise Exception.Create('The file "' + Name + '" cannot be displayed because SFM does not recognise the file type.');
|
||||
end;
|
||||
|
||||
dib := FreeImage_Load(t, PChar(name), 0);
|
||||
if Dib = nil then
|
||||
Close;
|
||||
PBH := FreeImage_GetInfoHeader(dib);
|
||||
PBI := FreeImage_GetInfo(dib^);
|
||||
|
||||
BPP := FreeImage_GetBPP(dib);
|
||||
|
||||
ShowWithAlphaItem.Enabled := BPP = 32;
|
||||
ShowAlphaItem.Enabled := BPP = 32;
|
||||
|
||||
if BPP = 32 then
|
||||
begin
|
||||
ImgView32.Bitmap.SetSize(FreeImage_GetWidth(dib), FreeImage_GetHeight(dib));
|
||||
|
||||
BP := PLONGWORD(FreeImage_GetBits(dib));
|
||||
for y := ImgView32.Bitmap.Height - 1 downto 0 do
|
||||
for x := 0 to ImgView32.Bitmap.Width - 1 do
|
||||
begin
|
||||
ImgView32.Bitmap.Pixel[x, y] := BP^;
|
||||
inc(BP);
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
BM := TBitmap.Create;
|
||||
|
||||
BM.Assign(nil);
|
||||
DC := GetDC(Handle);
|
||||
|
||||
BM.handle := CreateDIBitmap(DC,
|
||||
PBH^,
|
||||
CBM_INIT,
|
||||
PChar(FreeImage_GetBits(dib)),
|
||||
PBI^,
|
||||
DIB_RGB_COLORS);
|
||||
|
||||
ImgView32.Bitmap.Assign(BM);
|
||||
AlphaView.Bitmap.Assign(BM);
|
||||
|
||||
BM.Free;
|
||||
ReleaseDC(Handle, DC);
|
||||
end;
|
||||
FreeImage_Unload(dib);
|
||||
|
||||
OrigWidth := ImgView32.Bitmap.Width;
|
||||
OrigHeight := ImgView32.Bitmap.Height;
|
||||
|
||||
Caption := ExtractFileName( Name ) + ' (' + IntToStr(OrigWidth) +
|
||||
' x ' + IntToStr(OrigHeight) + ')';
|
||||
if BPP = 32 then
|
||||
Caption := Caption + ' + Alpha';
|
||||
|
||||
AlphaView.Bitmap.SetSize(OrigWidth, OrigWidth);
|
||||
|
||||
ImgView32.Hint := 'Name: ' + Name + #13 +
|
||||
'Width: ' + IntToStr(OrigWidth) + #13 +
|
||||
'Height: ' + IntToStr(OrigHeight) + #13 +
|
||||
'BPP: ' + IntToStr(BPP);
|
||||
|
||||
RecalcWindowSize;
|
||||
|
||||
Show;
|
||||
except
|
||||
on e:exception do
|
||||
begin
|
||||
Application.BringToFront;
|
||||
MessageDlg(e.message, mtInformation, [mbOK], 0);
|
||||
Close;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.ZoomInItemClick(Sender: TObject);
|
||||
begin
|
||||
FilterTimer.Enabled := False;
|
||||
if ImgView32.Bitmap.StretchFilter <> sfNearest then
|
||||
ImgView32.Bitmap.StretchFilter := sfNearest;
|
||||
FilterTimer.Enabled := True;
|
||||
|
||||
ImgView32.Scale := ImgView32.Scale * 2.0;
|
||||
RecalcWindowSize;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.ZoomOutItemClick(Sender: TObject);
|
||||
begin
|
||||
FilterTimer.Enabled := False;
|
||||
if ImgView32.Bitmap.StretchFilter <> sfNearest then
|
||||
ImgView32.Bitmap.StretchFilter := sfNearest;
|
||||
FilterTimer.Enabled := True;
|
||||
|
||||
ImgView32.Scale := ImgView32.Scale / 2.0;
|
||||
RecalcWindowSize;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.ActualSizeItemClick(Sender: TObject);
|
||||
begin
|
||||
FilterTimer.Enabled := False;
|
||||
if ImgView32.Bitmap.StretchFilter <> sfNearest then
|
||||
ImgView32.Bitmap.StretchFilter := sfNearest;
|
||||
FilterTimer.Enabled := True;
|
||||
|
||||
ImgView32.Scale := 1.0;
|
||||
|
||||
RecalcWindowSize;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.RecalcWindowSize;
|
||||
var
|
||||
Rect : TRect;
|
||||
CW, CH : integer;
|
||||
WSH, WSW : integer;
|
||||
TitleH : integer;
|
||||
BorderY : integer;
|
||||
BorderX : integer;
|
||||
begin
|
||||
CW := ImgView32.Bitmap.Width + GetSystemMetrics(SM_CXVSCROLL);
|
||||
CH := ImgView32.Bitmap.Height + GetSystemMetrics(SM_CYVSCROLL);
|
||||
|
||||
SystemParametersInfo( SPI_GETWORKAREA, 0, @Rect, 0);
|
||||
|
||||
WSH := Rect.Bottom - Rect.Top;
|
||||
WSW := Rect.Right - Rect.Left;
|
||||
TitleH := GetSystemMetrics(SM_CYCAPTION);
|
||||
BorderY := GetSystemMetrics(SM_CYSIZEFRAME) * 2;
|
||||
BorderX := GetSystemMetrics(SM_CXSIZEFRAME) * 2;
|
||||
|
||||
if (Top + CH + TitleH + BorderY > WSH) or (CH + TitleH + BorderY > WSH) then
|
||||
begin
|
||||
Top := Rect.Bottom - CH - BorderY;
|
||||
if Top < 0 then
|
||||
begin
|
||||
Top := 0;
|
||||
CH := WSH - TitleH - BorderY;
|
||||
CW := CW + GetSystemMetrics(SM_CXVSCROLL);
|
||||
|
||||
if CW + BorderX > WSW then
|
||||
CH := CH - GetSystemMetrics(SM_CYVSCROLL);
|
||||
end;
|
||||
end;
|
||||
|
||||
if (Left + CW + BorderX > WSW) or (CW + BorderX > WSW) then
|
||||
begin
|
||||
Left := Rect.Right - CW - BorderX;
|
||||
if Left < 0 then
|
||||
begin
|
||||
Left := 0;
|
||||
CW := WSW - BorderX;
|
||||
CH := CH + GetSystemMetrics(SM_CYVSCROLL);
|
||||
|
||||
if CH + TitleH + BorderY > WSH then
|
||||
CW := CW + GetSystemMetrics(SM_CXVSCROLL);
|
||||
end
|
||||
end;
|
||||
|
||||
ClientWidth := CW;
|
||||
ClientHeight := CH;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.ScrollBoxMouseWheel(Sender: TObject;
|
||||
Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
|
||||
var Handled: Boolean);
|
||||
begin
|
||||
FilterTimer.Enabled := False;
|
||||
if ImgView32.Bitmap.StretchFilter <> sfNearest then
|
||||
ImgView32.Bitmap.StretchFilter := sfNearest;
|
||||
FilterTimer.Enabled := True;
|
||||
|
||||
if WheelDelta < 0 then
|
||||
ImgView32.Scroll(0, 20)
|
||||
else
|
||||
ImgView32.Scroll(0, -20);
|
||||
Handled := True;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
var
|
||||
Amount : integer;
|
||||
begin
|
||||
FilterTimer.Enabled := False;
|
||||
if ImgView32.Bitmap.StretchFilter <> sfNearest then
|
||||
ImgView32.Bitmap.StretchFilter := sfNearest;
|
||||
FilterTimer.Enabled := True;
|
||||
|
||||
if ssShift in Shift then
|
||||
Amount := 20 * 2
|
||||
else
|
||||
Amount := 20;
|
||||
|
||||
case Key of
|
||||
VK_ESCAPE:
|
||||
Close;
|
||||
VK_UP:
|
||||
ImgView32.Scroll(0, -Amount);
|
||||
VK_DOWN:
|
||||
ImgView32.Scroll(0, Amount);
|
||||
VK_LEFT:
|
||||
ImgView32.Scroll(-Amount, 0);
|
||||
VK_RIGHT:
|
||||
ImgView32.Scroll(Amount, 0);
|
||||
VK_HOME:
|
||||
ImgView32.ScrollToCenter(0, 0);
|
||||
VK_END:
|
||||
ImgView32.ScrollToCenter(ImgView32.Bitmap.Width, ImgView32.Bitmap.Height);
|
||||
VK_NEXT:
|
||||
ImgView32.Scroll(0, (Trunc(ImgView32.Bitmap.Height div 4)));
|
||||
VK_PRIOR:
|
||||
ImgView32.Scroll(0, -(Trunc(ImgView32.Bitmap.Height div 4)));
|
||||
end;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.ShowAlphaItemClick(Sender: TObject);
|
||||
var
|
||||
x, y : integer;
|
||||
Col : TColor32;
|
||||
Alpha : TColor;
|
||||
begin
|
||||
if ShowAlphaItem.Checked then
|
||||
begin
|
||||
AlphaView.Visible := False;
|
||||
AlphaView.Bitmap.Delete;
|
||||
end
|
||||
else
|
||||
begin
|
||||
AlphaView.Bitmap.Width := ImgView32.Bitmap.Width;
|
||||
AlphaView.Bitmap.Height := ImgView32.Bitmap.Height;
|
||||
|
||||
for x := 0 to AlphaView.Bitmap.Width - 1 do
|
||||
for y := 0 to AlphaView.Bitmap.Height - 1 do
|
||||
begin
|
||||
Col := ImgView32.Bitmap.Pixel[x, y];
|
||||
Alpha := Col shr 24;
|
||||
AlphaView.Bitmap.Pixel[x, y] := Alpha + (Alpha shl 8) + (Alpha shl 16);
|
||||
end;
|
||||
AlphaView.Visible := True;
|
||||
end;
|
||||
ShowAlphaItem.Checked := not ShowAlphaItem.Checked;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.RotateClockwiseItemClick(Sender: TObject);
|
||||
var
|
||||
x : integer;
|
||||
y : integer;
|
||||
DestX : integer;
|
||||
DestY : integer;
|
||||
C : TColor32;
|
||||
begin
|
||||
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
|
||||
|
||||
ImgView32.BeginUpdate;
|
||||
ImgView32.Bitmap.Width := AlphaView.Bitmap.Height;
|
||||
ImgView32.Bitmap.Height := AlphaView.Bitmap.Width;
|
||||
|
||||
for x := 0 to AlphaView.Bitmap.Width - 1 do
|
||||
for y := 0 to AlphaView.Bitmap.Height - 1 do
|
||||
begin
|
||||
C := AlphaView.Bitmap.Pixel[x, y];
|
||||
|
||||
DestX := (ImgView32.Bitmap.Width - 1) - Y;
|
||||
DestY := X;
|
||||
|
||||
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
|
||||
end;
|
||||
|
||||
ImgView32.EndUpdate;
|
||||
ImgView32.Refresh;
|
||||
end;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.RotateAntiClockwiseItemClick(Sender: TObject);
|
||||
var
|
||||
x : integer;
|
||||
y : integer;
|
||||
DestX : integer;
|
||||
DestY : integer;
|
||||
C : TColor32;
|
||||
begin
|
||||
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
|
||||
|
||||
ImgView32.BeginUpdate;
|
||||
ImgView32.Bitmap.Width := AlphaView.Bitmap.Height;
|
||||
ImgView32.Bitmap.Height := AlphaView.Bitmap.Width;
|
||||
|
||||
for x := 0 to AlphaView.Bitmap.Width - 1 do
|
||||
for y := 0 to AlphaView.Bitmap.Height - 1 do
|
||||
begin
|
||||
C := AlphaView.Bitmap.Pixel[x, y];
|
||||
|
||||
DestX := Y;
|
||||
DestY := (ImgView32.Bitmap.Height - 1) -X;
|
||||
|
||||
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
|
||||
end;
|
||||
|
||||
ImgView32.EndUpdate;
|
||||
ImgView32.Refresh;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.ShowWithAlphaItemClick(Sender: TObject);
|
||||
begin
|
||||
if ShowWithAlphaItem.Checked then
|
||||
ImgView32.Bitmap.DrawMode := dmOpaque
|
||||
else
|
||||
ImgView32.Bitmap.DrawMode := dmBlend;
|
||||
ShowWithAlphaItem.Checked := not ShowWithAlphaItem.Checked;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.FlipHorizontalItemClick(Sender: TObject);
|
||||
var
|
||||
x : integer;
|
||||
y : integer;
|
||||
DestX : integer;
|
||||
DestY : integer;
|
||||
C : TColor32;
|
||||
begin
|
||||
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
|
||||
|
||||
ImgView32.BeginUpdate;
|
||||
ImgView32.Bitmap.Width := AlphaView.Bitmap.Width;
|
||||
ImgView32.Bitmap.Height := AlphaView.Bitmap.Height;
|
||||
|
||||
for x := 0 to AlphaView.Bitmap.Width - 1 do
|
||||
for y := 0 to AlphaView.Bitmap.Height - 1 do
|
||||
begin
|
||||
C := AlphaView.Bitmap.Pixel[x, y];
|
||||
|
||||
DestX := (ImgView32.Bitmap.Width - 1) -X;
|
||||
DestY := Y;
|
||||
|
||||
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
|
||||
end;
|
||||
|
||||
ImgView32.EndUpdate;
|
||||
ImgView32.Refresh;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.FilpVerticalItemClick(Sender: TObject);
|
||||
var
|
||||
x : integer;
|
||||
y : integer;
|
||||
DestX : integer;
|
||||
DestY : integer;
|
||||
C : TColor32;
|
||||
begin
|
||||
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
|
||||
|
||||
ImgView32.BeginUpdate;
|
||||
ImgView32.Bitmap.Width := AlphaView.Bitmap.Width;
|
||||
ImgView32.Bitmap.Height := AlphaView.Bitmap.Height;
|
||||
|
||||
for x := 0 to AlphaView.Bitmap.Width - 1 do
|
||||
for y := 0 to AlphaView.Bitmap.Height - 1 do
|
||||
begin
|
||||
C := AlphaView.Bitmap.Pixel[x, y];
|
||||
|
||||
DestX := X;
|
||||
DestY := (ImgView32.Bitmap.Height - 1) - Y;
|
||||
|
||||
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
|
||||
end;
|
||||
|
||||
ImgView32.EndUpdate;
|
||||
ImgView32.Refresh;
|
||||
end;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.FilterTimerTimer(Sender: TObject);
|
||||
begin
|
||||
FilterTimer.Enabled := False;
|
||||
ImgView32.Bitmap.StretchFilter := sfSPline;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.ImgView32Scroll(Sender: TObject);
|
||||
begin
|
||||
FilterTimer.Enabled := False;
|
||||
if ImgView32.Bitmap.StretchFilter <> sfNearest then
|
||||
ImgView32.Bitmap.StretchFilter := sfNearest;
|
||||
FilterTimer.Enabled := True;
|
||||
end;
|
||||
// -----------------------------------------------------------------------------
|
||||
procedure TMainForm.OpenImageItemClick(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog.Execute then
|
||||
begin
|
||||
try
|
||||
Screen.Cursor := crHourGlass;
|
||||
LoadImage(OpenDialog.FileName);
|
||||
finally
|
||||
Screen.Cursor := crDefault;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -0,0 +1,8 @@
|
||||
This is a simple image viewing application that uses the FreeImage library to display images in many different formats.
|
||||
|
||||
The app displays the image whose name is passed in as a command line argument.
|
||||
|
||||
|
||||
To compile the app you will also need the Graphics32 library available from www.g32.org. It has been tested with version 1.5.1 of Graphics32.
|
||||
|
||||
SJB.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
Reference in New Issue
Block a user