Save TBitmap image to Jpeg format image in Delphi

CK CK 3788 
Created at  
717 0 0
Delphi supports Jpeg unit as well as Bitmap unit for image processing. Following example convert and save bitmap into jpeg format. The source format must be TBitmap instance.

unit jpeg;

procedure BitmapToJpeg(FileName: string; Img:TGraphic);
var
  m_jpeg: TJpegImage;
  m_bitmap: TBitmap;
begin
  try
    m_jpeg:= TJpegImage.Create;

    m_bitmap := TBitmap.Create;
    m_bitmap.Width := Img.Width;
    m_bitmap.Height := Img.Height;
    m_bitmap.Canvas.Draw( 0, 0, Img);
//    m_bitmap.Canvas.StretchDraw( 0, 0, , ...,Img);

    m_jpeg.Assign( m_bitmap);

    m_jpeg.SaveToFile( FileName);
  finally
    m_jpeg.Free;
  end;
end;


Tags Argc Argv Command Line String Jpeg TBitmap TColor TImage TJpegImage Facebook X
Comments 0
Similar posts
  1. Rotate Bitmap (any angle, any center of rotation)
    409
  2. Show *any* graphics as Glyph on a SpeedButton
    549
  3. Paint a Form with a tiled bitmap image
    419
  4. Grayscaling a bitmap ?
    537
  5. How to convert an ICO to a BMP
    368
  6. Convert a BMP to a JPG
    415
  7. Array of arguments passed to script in PHP
    97
  1. Delphi API to get windows temporary directory
    586
  2. Delphi API to get the current working directory
    1,254
  3. How to resize PNG file in Delphi ?
    1,223
  4. Get the length of arrays and a string
    1,742
  5. Delphi Pointer Types
    22,097
  6. How to read/wrtie INI file in Delphi ?
    3,123
  7. How to get file created time, modified time, and last accessed time ?
    3,348
  8. Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ...
    645
  9. When subject is crashing in TIdSMTP VCL
    620
  10. How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL
    1,084
  11. How to encode subject content when sending mail with TIdMessage ?
    1,075
  12. Base64 Encoding/Decoding function for Delphi
    1,176
  13. How to send email by TIdSMTP VCL ?
    1,022
  14. How to return exit code such as exit() function in C/C++ ?
    670
  15. How to get parameter string ?
    1,249
  16. How to get screen resolution in case of using multiple monitors ?
    452
  17. How to turn off monitor ?
    435
  18. Find File at certain directory in Delphi
    441
  19. Sending email messages in .Net
    1,041
  20. Delphi for .Net Code Folding keyboard shortcuts
    530
  21. How to encrypt a string
    468
  22. Creating thumbnail images
    865
  23. Technology sharing related with software development. Specially content will be focused to programming language, and embedded systems.
    855
  24. How to speed up access to the RichTextBox Lines property
    832
  25. Window flashing
    379
  26. How to use TTF Font Without Installing
    1,122
  27. How to show window contents while dragging
    461
  28. How to save text from Clipboard to a file
    573
  29. How to send char as message to another application
    548
  30. How to restrict mouse movement
    412
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    28
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    55
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    49
  4. How do I create animated background for Google Meet?
    22,830
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    271
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    103
  7. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    168
  8. Invalid Auction Storms in Ad Tech
    106
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    207
  10. The Two Clocks of Ad Server Architecture
    77
  11. Frequency Cap Architecture Overview
    526
  12. Collecting Proof-of-Play from 100,000 Screens
    152
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    302
  14. What is RedisVL?
    114
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    246
  16. TPU & GPU Cluster Management Tools
    257
  17. The Concept of Scaffolding in AI Agents
    244
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    596
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    267
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    353
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    206
  22. Machine Learning: Training vs. Ranking
    229
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    228
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    202
  25. Designing a Data Curation System Around a Vector Database
    230
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    671
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    200
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    232
  30. Understanding Data Lineage
    271