ionet
asked on
Program ran out of memory!
Hi Experts,
I really can't figure this out but what my program does is have a picture, and when you drage your mouse over it, it masks it with a color. When i drag it over the form and picture a lot of times, I get a "not enough memory to complete" task error. Please help.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, jpeg;
type
TForm1 = class(TForm)
Image1: TImage;
SpeedButton1: TSpeedButton;
ColorDialog1: TColorDialog;
SaveDialog1: TSaveDialog;
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure SpeedButton1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1; //The Form lol
OrginalPic : TImage; //Orginal Picture
MyPicState : Boolean; //true are false varible
implementation
{$R *.dfm}
procedure TForm1.Image1MouseMove(Sen der: TObject; Shift: TShiftState; X,
Y: Integer);
var
Pic : TBitmap;//Bitmap
AForm : Word;//A Unsigned 4 byte number
damn : Thandle;//handle
blah : HPALETTE;
begin
Pic := TBitmap.Create; //making a pic a bitmap
Pic.Assign(Image1.Picture. Graphic); //assign the image to pic
Pic.SaveToClipboardFormat( AForm,damn ,blah);//s ave the bitmap in a clipboard
Pic.Free;//freeing the pic from memory
Image1.Picture.LoadFromCli pboardForm at(AForm,d amn,blah); //load the pic saved to the clippedbaord
Image1.Canvas.Pen.Mode := pmMask;//puts the translucent color over the image
Image1.Canvas.Brush.Color := ColorDialog1.Color;//Set the brush color to to color dialog color
Image1.canvas.Rectangle(0, 0,Image1.W idth,Image 1.Height); //Paint over the whole image
MyPicState := False; //if the mouse is already over it make it stop loading over and over to save memory
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ColorDialog1.Color := $00FF00;//Color Green In hex just like the rgb function
MyPicState := True;//Set Pic State To True
OrginalPic := TImage.Create(self); //Make the orginalpic
OrginalPic.Picture := Image1.Picture; //save the orginal pic thats from startup
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
OrginalPic.Free; //when the programs done free the orginalpic
end;
procedure TForm1.FormMouseMove(Sende r: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if MyPicState = False then
begin
Image1.Picture := OrginalPic.Picture; //if the mouse is over the form the pic is back to normal
MyPicState := True; //MyPicState is true so when you put the mouse over the pic it will highlight
end;
end;
I really can't figure this out but what my program does is have a picture, and when you drage your mouse over it, it masks it with a color. When i drag it over the form and picture a lot of times, I get a "not enough memory to complete" task error. Please help.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, jpeg;
type
TForm1 = class(TForm)
Image1: TImage;
SpeedButton1: TSpeedButton;
ColorDialog1: TColorDialog;
SaveDialog1: TSaveDialog;
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure SpeedButton1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1; //The Form lol
OrginalPic : TImage; //Orginal Picture
MyPicState : Boolean; //true are false varible
implementation
{$R *.dfm}
procedure TForm1.Image1MouseMove(Sen
Y: Integer);
var
Pic : TBitmap;//Bitmap
AForm : Word;//A Unsigned 4 byte number
damn : Thandle;//handle
blah : HPALETTE;
begin
Pic := TBitmap.Create; //making a pic a bitmap
Pic.Assign(Image1.Picture.
Pic.SaveToClipboardFormat(
Pic.Free;//freeing the pic from memory
Image1.Picture.LoadFromCli
Image1.Canvas.Pen.Mode := pmMask;//puts the translucent color over the image
Image1.Canvas.Brush.Color := ColorDialog1.Color;//Set the brush color to to color dialog color
Image1.canvas.Rectangle(0,
MyPicState := False; //if the mouse is already over it make it stop loading over and over to save memory
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ColorDialog1.Color := $00FF00;//Color Green In hex just like the rgb function
MyPicState := True;//Set Pic State To True
OrginalPic := TImage.Create(self); //Make the orginalpic
OrginalPic.Picture := Image1.Picture; //save the orginal pic thats from startup
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
OrginalPic.Free; //when the programs done free the orginalpic
end;
procedure TForm1.FormMouseMove(Sende
Y: Integer);
begin
if MyPicState = False then
begin
Image1.Picture := OrginalPic.Picture; //if the mouse is over the form the pic is back to normal
MyPicState := True; //MyPicState is true so when you put the mouse over the pic it will highlight
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.