[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

rgb colour values of a jpeg image?

Posted on 2000-05-11
5
Medium Priority
?
570 Views
Last Modified: 2013-11-19
Hi guys!

I have a form with a Timage (in Delphi 5) and I loaded it with a jpeg file. I want to know the RGB values for a particular pixel in the jpeg file.

If I load the Timage with a bmp file, I can find the rgb values easily using this code:

      L := Form1.Image1.Picture.Bitmap.Canvas.Pixels[x,y];
      R := R + ((L shr 16) and $FF);
      G := G + ((L shr 8) and $FF);
      B := B + (L and $FF);

It does not work with jpeg images. Any suggestion?

thanks in advance,
Manuel López (lopem)
0
Comment
Question by:lopem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:raidos
ID: 2803577
I beleive that the JPG is not in Image1.Picture.Bitmap but rather
Image1.Picture.Graphic

But i don't know how to address the canvas for jpg's

Maybe you need to convert it to bitmap and draw it into the Image1.Picture.Bitmap.Canvas yourself

Good luck

//raidos
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2803607
TJPEGImage is a TGraphic descentant. This causes TPicture to throw away the image data when accessing its Bitmap property. The solution is to use a separate TPicture to load the JPG and do an Bitmap.Assign(JPGPicture.Graphic) to the image before acessing its canvas.

Ciao, Mike
0
 
LVL 3

Author Comment

by:lopem
ID: 2804954
Thanks Raidos and Lischke...

Just tell me something Lischke, how I can assign a jpg a bitmap? I tried this, but didnt work (from the delphi 5 help file):

var
 BitMap1,BitMap2 : TBitMap;
 MyFormat : Word;
begin
   BitMap2 := TBitMap.Create;
   BitMap1 := TBitMap.Create;
try
   BitMap1.LoadFromFile('c:\images\image001.jpg');
   BitMap2.Assign(BitMap1);     // Copy BitMap1 into BitMap2
   BitMap2.Dormant;             // Free up GDI resources
   BitMap2.FreeImage;           // Free up Memory.
   Canvas.Draw(20,20,BitMap2);  // Note that previous calls don't lose the image

   BitMap2.Monochrome := true;
   Canvas.Draw(80,80,BitMap2);
   BitMap2.ReleaseHandle;       // This will actually lose the bitmap;
 finally
   BitMap1.Free;
   BitMap2.Free;
 end;
end;

Can you send a simple example of loading a jpeg, do a bitmap assign so I can use its canvas?

Thanks a lot,
Manuel
0
 
LVL 10

Accepted Solution

by:
Lischke earned 90 total points
ID: 2805003
This is wrong because you cannot load a jpg with a TBitmap. The easiest way is to use the polymorphic abilitiy of TPicture.

  Pic := TPicture.Create;
  Pic.LoadFromFile('MyImage.jpg');
  Form1.Image1.Picture.Bitmap.Assign(Pic.Graphic);
  Pic.Free;

Now it is safe to access the bitmap's canvas of Image1.

Ciao, Mike
0
 
LVL 3

Author Comment

by:lopem
ID: 2806374
Just fot the sake of completeness... To use Lischke's idea you have to declare the unit jpeg in the uses section...

Best regards,
Manuel López (lopem)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.
Suggested Courses

649 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