Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:56:40+00:00 2026-06-06T00:56:40+00:00

I have a paintbox and I draw a TBitmap like this: procedure MyForm.PaintBoxPaint(Sender: TObject);

  • 0

I have a paintbox and I draw a TBitmap like this:

procedure MyForm.PaintBoxPaint(Sender: TObject); // ONPAINT
begin
 PaintBox.Canvas.Lock;
 MyBitMap.Canvas.Lock;
 PaintBox.Canvas.Draw(0, 0, MyBitMap);
 PaintBox.Canvas.UnLock;
 MyBitMap.Canvas.UnLock;
end;

I would like to “map”/”copy” a JPEG or BMP from the PaintBox.
There are some challenges tho that I have to think about first.
The first thing is that I want to save a JPEG or BMP to a file that supports a WidePath/WideFileName. I use Delphi 7 and the .SaveToFile procedures only supports AnsiPaths/AnsiFileNames. The next thing is that I want to make a copy that is independent from the “MainGUI Thread”. So the GUI should be still active and drawing to the paintbox while it saves the copy in the background (so NO TTimer). The last thing is the actual filename of the “copy”. I would like to set a counter that goes from 1.jpg … to 2.jpg … to N.jpg
The problem is the counting of an Integer that can cause access violations due to every function tries to increment the counter.

My Idea was the following:

A structure for the saving Thread:

type
 PTRTSaveImage = ^TSaveImage;
 TSaveImage = record
 Number : Integer;
 Pic    : TBitMap;
end;

The actual SaveImageThread:

function SaveImageToHDD ( p : pointer ) : Integer; stdcall;
var
 jpg      : TJpegImage;
 jpgStr   : TStringStream;
 _infos   : TSaveImage;
begin
 CopyMemory(@_infos, p, SizeOf(_infos));
 jpg    := TJpegImage.Create;
 jpgStr := TStringStream.Create ('');
 jpg.assign (_infos.Pic);
 _infos.Pic.Free;
 jpg.SaveToStream(jpgStr);
 jpg.Free;
 StrToFile ('C:\' + inttostr(_infos.Number) + '.jpg',0,jpgStr.DataString); // for WidePath/WideFileName Support.
 jpgStr.Free;
end;

That’s how I call the Thread:

procedure MyForm.PaintBoxPaint(Sender: TObject); // ONPAINT
var
 Saving : PTRTSaveImage;
 BackUp : TBitMap;
begin
 PaintBox.Canvas.Lock;
 MyBitMap.Canvas.Lock;
 PaintBox.Canvas.Draw(0, 0, MyBitMap);
 BackUp := TBitMap.Create;
 BackUp.Assign (MyBitMap); // Immediate copy of the actual drawing! 
 Saving   := PTRTSaveImage(LocalAlloc(LPTR, SizeOf(TSaveImage)));
 Saving^.Pic    := BackUp;
 Saving^.Number := Counter;
 inc (Counter);
 PaintBox.Canvas.UnLock;
 MyBitMap.Canvas.UnLock;
end;

it takes a few pictures just fine but then the debugger shows me an exception:

Debugger Fault Notification
Project C:….exe faulted with message: ‘application-defined exception (code 0x0eedfade) at 0x759d9617’. Process Stopped. Use Step or Run to continue.

Is there any “better way” to do this? Saving and drawing at the same time…?!

Thanks for your help.

EDIT:

Then I also thought about just making 1 thread as a replacement for a TTimer that goes like this:

function SaveImages ( p : TMyForm ) : Integer; stdcall
var
 jpg    : TJpegImage; 
 jpgStr : TStringStream;
begin
while true do begin   // ---> constant LOOP that saves pictures in the intervall
 sleep (1000);        // Intervall
 jpg    := TJpegImage.Create;
 jpg.assign (p.MyBitMap);
 jpgStr := TStringStream.Create ('');
 jpg.SaveToStream(jpgStr);
 jpg.Free;
 StrToFile ('C:\' + inttostr(p.Counter) + '.jpg',0,jpgStr.DataString); // for WidePath/WideFileName Support.  
 inc (p.Counter);  
 jpgStr.Free;
end;
end;

but the same error/exception occurs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:56:44+00:00Added an answer on June 6, 2026 at 12:56 am

    AVI file…I did wonder… I would create a new Paintbox control derived from TPaintBox. (You may have done that already?)

    Add a counter property and code to it that captures the canvas using BitBlit to a Bmp then creates a thread to convert and save the bitmap as a jpg, and increments the counter when it it starts. (You will need to use Synchronize for that call). Name it say CaptureCanvas.

    Finally add a method called say afterChange or afterTimePeriod that calls captureCanvas. Make sure you have a try … finally that ensures the bitmap and Jpeg are destroyed if anything goes wrong with the saving. Its then all in one place(inside TNewPaintbox, and if it gets behind then the images being created already have their index and you won’t save them out of order…. just an idea 🙂

    Sorry Meant to add the form code would then simplify to:

    Form1.Paintboxpaint()
    begin
    .
    .
    PaintBox.Canvas.Draw(x, y, bitmap);
    Paintbox.AfterChange;
    .
    

    Sorry for brevity, editing the answer and can’t see the original post

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Using the following code in Delphi 2007: procedure TfrmTest.PaintBox1Paint(Sender: TObject); const Rect_Size = 10;
have a php code like this,going to convert it in to C#. function isValid($n){
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have converted devise new session from erb to Haml but doens't work, this is
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:
have Googled the cr*p out of this one so apologies if the answer is
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.