Bitmap conversion now operational

This commit is contained in:
Raymond 2010-05-11 20:52:17 +02:00
parent 229cdd6886
commit 12cb2c1513
3 changed files with 99 additions and 22 deletions

View File

@ -3,36 +3,65 @@ object BitmapConvForm: TBitmapConvForm
Height = 240 Height = 240
Top = 192 Top = 192
Width = 320 Width = 320
Caption = 'BitmapConvForm' Caption = 'Bitmap conversion'
ClientHeight = 240 ClientHeight = 240
ClientWidth = 320 ClientWidth = 320
Constraints.MinHeight = 240
Constraints.MinWidth = 320
LCLVersion = '0.9.29' LCLVersion = '0.9.29'
object Button1: TButton object ToStringButton: TButton
Left = 192 Left = 192
Height = 36 Height = 36
Top = 184 Top = 184
Width = 113 Width = 113
Caption = 'Button1' Anchors = [akRight, akBottom]
Caption = 'To string'
OnClick = ToStringButtonClick
TabOrder = 0 TabOrder = 0
end end
object CheckBox1: TCheckBox object PadOutput: TCheckBox
Left = 224 Left = 192
Height = 17 Height = 17
Top = 152 Top = 160
Width = 71 Width = 71
Caption = 'CheckBox1' Anchors = [akRight, akBottom]
Caption = 'Pad output'
Checked = True
State = cbChecked
TabOrder = 1 TabOrder = 1
end end
object Button2: TButton object OpenButton: TButton
Left = 12 Left = 12
Height = 36 Height = 36
Top = 184 Top = 184
Width = 90 Width = 90
Anchors = [akRight, akBottom]
Caption = 'Open' Caption = 'Open'
OnClick = Button2Click OnClick = OpenButtonClick
TabOrder = 2 TabOrder = 2
end end
object OpenPictureDialog1: TOpenPictureDialog object GroupBox: TGroupBox
Left = 12
Height = 145
Top = 8
Width = 284
Anchors = [akTop, akLeft, akRight, akBottom]
Caption = 'Image'
ClientHeight = 127
ClientWidth = 280
TabOrder = 3
object ImagePreview: TImage
Left = 0
Height = 127
Top = 0
Width = 280
Align = alClient
Center = True
end
end
object OpenPictureDialog: TOpenPictureDialog
FilterIndex = 2
Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing, ofViewDetail]
left = 128 left = 128
top = 184 top = 184
end end

View File

@ -5,22 +5,26 @@ unit bitmapconv;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, bitmaps, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, EditBtn, ExtDlgs; StdCtrls, EditBtn, ExtDlgs, ExtCtrls;
type type
{ TBitmapConvForm } { TBitmapConvForm }
TBitmapConvForm = class(TForm) TBitmapConvForm = class(TForm)
Button1: TButton; GroupBox: TGroupBox;
Button2: TButton; ToStringButton: TButton;
CheckBox1: TCheckBox; OpenButton: TButton;
OpenPictureDialog1: TOpenPictureDialog; PadOutput: TCheckBox;
procedure Button2Click(Sender: TObject); ImagePreview: TImage;
OpenPictureDialog: TOpenPictureDialog;
procedure OpenButtonClick(Sender: TObject);
procedure ToStringButtonClick(Sender: TObject);
private private
{ private declarations } { private declarations }
public public
dispPic : TMufasaBitmap;
{ public declarations } { public declarations }
end; end;
@ -28,15 +32,59 @@ var
BitmapConvForm: TBitmapConvForm; BitmapConvForm: TBitmapConvForm;
implementation implementation
uses
SimbaUnit;
const
BmpSizeTxt = '(%dx%d)';
{$R *.lfm} {$R *.lfm}
{ TBitmapConvForm } { TBitmapConvForm }
procedure TBitmapConvForm.Button2Click(Sender: TObject); procedure TBitmapConvForm.OpenButtonClick(Sender: TObject);
var
x : TMufasaBitmap;
begin begin
if OpenPictureDialog1.Execute then if OpenPictureDialog.Execute then
writeln(OpenPictureDialog1.FileName); begin
try
ImagePreview.Picture.LoadFromFile(OpenPictureDialog.FileName);
GroupBox.Caption:= Format(BmpSizeTxt,[ImagePreview.Picture.Width,ImagePreview.Picture.Height]);
x := TMufasaBitmap.Create;
x.LoadFromFile(OpenPictureDialog.FileName);
if dispPic <> nil then
dispPic.Free;
dispPic := x;
except
formWritelnEx('ERROR loading the file: ' + OpenPictureDialog.FileName);
ImagePreview.Picture := nil;
if dispPic <> nil then
FreeAndNil(dispPic);
end;
end;
end;
procedure TBitmapConvForm.ToStringButtonClick(Sender: TObject);
var
str : string;
strend : string;
len : integer;
begin
if dispPic <> nil then
begin
str := ' Bmp := BitmapFromString('+
inttostr(disppic.Width)+ ', ' + inttostr(disppic.height) +', '#39 + dispPic.ToString;
strend := #39 +');';
len := length(str);
if PadOutput.Checked then
while Len > 65 do
begin
formWritelnEx(Copy(str,1,62) + #39 + ' +');
delete(str,1,62);
str := StringOfChar(' ',8) + #39 + str;
len := length(str);
end;
formWritelnEx(str + strend);
end;
end; end;
end. end.

View File

@ -1349,7 +1349,7 @@ object SimbaForm: TSimbaForm
OnClick = MenuItemSettingsButtonClick OnClick = MenuItemSettingsButtonClick
end end
object MenuItemBitmapConv: TMenuItem object MenuItemBitmapConv: TMenuItem
Caption = 'New Item50' Caption = '&Bitmap conversion'
OnClick = MenuItemBitmapConvClick OnClick = MenuItemBitmapConvClick
end end
object MenuItemDivider10: TMenuItem object MenuItemDivider10: TMenuItem