Solved

Get pixel color of a jpg in a TImage

Posted on 2013-11-07
1
2,702 Views
Last Modified: 2013-11-19
Hi Experts,

I need to get the pixel color of a jpg image inside of TImage. How can I do this ?

Something like this:

var
  pixel_color    : TColor;
begin
  pixel_color := Image1.Canvas.Pixels[0, 0];
end;

But this code only works to BMP image.

I am using Delphi Xe4

Thanks for some help
Alexandre
0
Comment
Question by:alpires
1 Comment
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39632236
Here is small example:
var
  jpeg: TJPEGImage;
  bmp: Tbitmap;
begin
  jpeg := TJPEGImage.Create;
  try
    jpeg.LoadFromFile('c:\test.jpg');
    bmp := Tbitmap.Create;
    try
      bmp.PixelFormat := pf24bit;
      bmp.Width := jpeg.Width;
      bmp.Height:= jpeg.Height;
      bmp.Assign(jpeg);
      //access pixel
      ShowMessage(IntToHex(Cardinal(bmp.Canvas.Pixels[1, 1]), 8));
    finally
      bmp.Free;
    end;
  finally
    jpeg.Free;
  end;

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question