Solved

Get pixel color of a jpg in a TImage

Posted on 2013-11-07
1
2,603 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Line meaning 9 82
Copy Files - Python 7 72
creating threads in delphi 1 82
RESTRequest Parameter 4 12
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now