I decided to learn lazarus and pascal in order to make a simple image compression program. Of course there are some programs that do that but...
1) I dont want to install .net framework
2) I want it to be crossplatform(win,linux)
3) And most important i want to have a good time creating something.
After i made the basic stuff, like opening an image show it on a picture box then compress and save it, i decided to try and add features. One feature that i am writing right now is the ability to paste an image from clipboard and then compressed it. I will add here the paste procedure and the compress procedure. My problem is that the compress procedure checks for Assigned(pic). Well i am a complete noob (3 days into lazarus) and i dont know how to tell my program that i have a pic from the clipboard so i can pass that check. So if anyone has time please give me a hand. Thank you.
[paste from clipboard code]
procedure Tform1.menupasteclipClick(Sender: TObject);
var
tempBitmap: TBitmap;
PictureAvailable: boolean = False;
begin
// we determine if any image is on clipboard
if (Clipboard.HasFormat(PredefinedClipboardFormat(pcfDelphiBitmap))) or
(Clipboard.HasFormat(PredefinedClipboardFormat(pcfBitmap))) then
PictureAvailable := True;
if PictureAvailable then
begin
tempBitmap := TBitmap.Create;
if Clipboard.HasFormat(PredefinedClipboardFormat(pcfDelphiBitmap)) then
tempBitmap.LoadFromClipboardFormat(PredefinedClipboardFormat(pcfDelphiBitmap));
if Clipboard.HasFormat(PredefinedClipboardFormat(pcfBitmap)) then
tempBitmap.LoadFromClipboardFormat(PredefinedClipboardFormat(pcfBitmap));
//Image1.Width := tempBitmap.Width;
//Image1.Height := tempBitmap.Height;
image1.Canvas.Draw(0, 0, tempBitmap);
lbl_size.Caption:='Width x Height: ' + inttostr(tempbitmap.Width) + ' x ' +
inttostr(tempbitmap.Height);
image1.Picture.Bitmap.Assign(tempBitmap);
tempBitmap.Free;
end
else
begin
ShowMessage('No image is found on clipboard');
end;
end;
[compression code]
procedure Tform1.btn_convertClick(Sender: TObject);
var
MyStream: TMemoryStream;
begin
if Assigned(pic) then begin
if Assigned(jpg) then FreeAndNil(jpg);
jpg:=TJPEGImage.Create;
try
jpg.CompressionQuality:=Slider.Position;
jpg.Assign(pic.Bitmap);
MyStream := TMemoryStream.create;
jpg.SaveToStream(MyStream);
MyStream.Position:=0;
finally
image2.Picture.LoadFromStream(MyStream);
FreeAndNil(MyStream);
end;
end;
btn_save.Enabled:=true;
menusave.Enabled:=true;
end;
By the way its pretty impressive what a noob can do in lazarus. So a big thanks to all the devs for this amazing tool.
http://tinypic.com/r/2vjq001/9