Solved

Get pixel color of a jpg in a TImage

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This video teaches viewers about errors in exception handling.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

16 Experts available now in Live!

Get 1:1 Help Now