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 6532725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:02:21+00:00 2026-05-25T10:02:21+00:00

I have a routine procedure DrawStuff(ACanvas: TCanvas; const ARect: TRect) that draws something to

  • 0

I have a routine procedure DrawStuff(ACanvas: TCanvas; const ARect: TRect) that draws something to a specified rectangle on a TCanvas. At the moment I call DrawStuff with a PaintBox’s canvas. Now I’m adding a Save as option, in which the user shall be able to select from a variety of file formats (bmp, wmf, jpg, … – preferrably as many TGraphic descendants as possible) to save the results of DrawStuff to.

Drawing to a TMetafile and saving that as “bla.bmp” or Assigning it to a TPicture doesn’t work correctly – e.g. it produces files with extension “.bmp” that aren’t bitmaps. Right now I can’t figure a solution that doesn’t involve special-casing every single file format:

  • bmp – Use TBitmap.Canvas.
  • wmf/emf: Use TMetafileCanvas.
  • etc. etc.

Do you know have any ideas for me?

  • 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-05-25T10:02:22+00:00Added an answer on May 25, 2026 at 10:02 am

    I guess a “dumb” conversion would probably as simple as this :

    type
      TGraphicTypeEnum = (gteBMP, gteJPG, gteTIF, gtePNG);
    
    procedure SaveGraphicAs(AGraphic : TGraphic; AGraphicType : TGraphicTypeEnum; AFileName : String);
    var vGraphicClass : TGraphicClass;
        vTargetGraphic : TGraphic;
        vBmp : TBitmap;
    begin
    
      case AGraphicType of
        gteBMP : vGraphicClass := TBitmap;
        gtejpg : vGraphicClass := TJPEGImage;
        gtetif : vGraphicClass := TWICImage;
        gtepng : vGraphicClass := TPngImage;
      else
        // EXIT; or raise...
      end;
      if aGraphic is vGraphicClass then //As suggested by Rob Kennedy
        AGraphic.SaveToFile(AFileName)
      else
      begin
        vBmp := nil;
        vTargetGraphic := vGraphicClass.Create;
        try
          vBmp := TBitmap.Create;
          vBmp.Assign(AGraphic);
          vTargetGraphic.Assign(vBmp);
          vTargetGraphic.SaveToFile(aFileName);
        finally
          vTargetGraphic.Free;
          vBmp.Free;
        end;
      end;
    end;
    

    Assigning to a TPicture didn’t work, as when you assign to a TPicture, TPicture will convert the graphic to the class you are assigning from.

    Note that in my example, there is 2 layers of conversion as the original image is converted to bitmap before being converted to the final format. There can be quite a bit of loss of information in the process. Most (all?) graphic type know how to convert to and from TBitmap, but TJPEGImage has no idea how to convert to TPngImage and vice versa.

    More efficient conversion method can be developed that keeps transparency and other effects specific to a file format, but that is beyong my knowledge. But depending on your needs, that might be sufficient.

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

Sidebar

Related Questions

If I have a routine that can throw an ArgumentException in two places, something
I recently ran across a routine that looks something like this: procedure TMyForm.DoSomething(list: TList<TMyObject>;
I have this routine that calculates the seconds-to-date for a struct tm . On
I have a routine that examines thousands of records looking for discrepancies. This can
I have a routine that dynamically changes a select list's selected option when the
I have a little routine that's run under Linux and Windows written in C
I have a javascript routine that is performing actions on a group of checkboxes,
I have this routine, I want to save that delta to count the days
I have a routine that takes a list of strings as a parameter, but
I have the following MySQL routine: DELIMITER $$ CREATE DEFINER=`root`@`%` PROCEDURE `getGroupOrders`(grp INT, ord

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.