?
Solved

Display RGB channels of image

Posted on 2011-02-16
4
Medium Priority
?
454 Views
Last Modified: 2012-05-11
I have an image inside a TImage component, I want to display each channel color inside a different TImage.
0
Comment
Question by:dc_mo
[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
4 Comments
 

Author Comment

by:dc_mo
ID: 34907374
Thanks but they're not relevant to my question.
0
 
LVL 12

Accepted Solution

by:
Hypo earned 2000 total points
ID: 34907619
Hi,
Check out the sample below... Load an image into Image1, and then press the button...

The Channels are singled out by using the pmMask mode on the Canvas.pen object... This mode perofrms an AND with the Color property of the Pen and Brush, on each pixel of the area it draws to... so a simple way to get RGB channels is just to set this mode along with the color you want to single out, and then just draw a rectangle over the whole image.

(I Attached the .pas and .dfm files as code snippets)

/Hypo


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, pngimage;

type
  TForm1 = class(TForm)
    Image1: TImage;
    ImageRed: TImage;
    ImageGreen: TImage;
    ImageBlue: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var aColorBmp : TBitmap;
begin
  aColorBmp := TBitmap.Create;
  try
    // Get the picture into a bitmap...
    aColorBmp.PixelFormat := pf32bit;
    aColorBmp.SEtSize(Image1.Picture.Width, Image1.Picture.Height);
    aColorBmp.Canvas.Draw(0, 0, Image1.Picture.Graphic);
    // Mask out red component...
    ImageRed.Picture.Bitmap.Assign(aColorBmp);
    ImageRed.Picture.Bitmap.Canvas.Pen.Mode := pmMask;
    ImageRed.Picture.Bitmap.Canvas.Pen.Color := RGB(255, 0, 0);
    ImageRed.Picture.Bitmap.Canvas.Brush.Color := RGB(255, 0, 0);
    ImageRed.Picture.Bitmap.Canvas.Rectangle(0, 0, ImageRed.Picture.Width, ImageRed.Picture.Height);
    // Mask out red component...
    ImageGreen.Picture.Bitmap.Assign(aColorBmp);
    ImageGreen.Picture.Bitmap.Canvas.Pen.Mode := pmMask;
    ImageGreen.Picture.Bitmap.Canvas.Pen.Color := RGB(0, 255, 0);
    ImageGreen.Picture.Bitmap.Canvas.Brush.Color := RGB(0, 255, 0);
    ImageGreen.Picture.Bitmap.Canvas.Rectangle(0, 0, ImageGreen.Picture.Width, ImageGreen.Picture.Height);
    // Mask out red component...
    ImageBlue.Picture.Bitmap.Assign(aColorBmp);
    ImageBlue.Picture.Bitmap.Canvas.Pen.Mode := pmMask;
    ImageBlue.Picture.Bitmap.Canvas.Pen.Color := RGB(0, 0, 255);
    ImageBlue.Picture.Bitmap.Canvas.Brush.Color := RGB(0, 0, 255);
    ImageBlue.Picture.Bitmap.Canvas.Rectangle(0, 0, ImageBlue.Picture.Width, ImageBlue.Picture.Height);
  finally
    FreeAndNil(aColorBmp);
  end;
end;

end.

Open in new window

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 526
  ClientWidth = 688
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 8
    Top = 8
    Width = 169
    Height = 169
    Stretch = True
  end
  object ImageRed: TImage
    Left = 8
    Top = 214
    Width = 169
    Height = 169
    Stretch = True
  end
  object ImageGreen: TImage
    Left = 183
    Top = 214
    Width = 169
    Height = 169
    Stretch = True
  end
  object ImageBlue: TImage
    Left = 358
    Top = 214
    Width = 169
    Height = 169
    Stretch = True
  end
  object Button1: TButton
    Left = 102
    Top = 183
    Width = 75
    Height = 25
    Caption = 'View RGB'
    TabOrder = 0
    OnClick = Button1Click
  end
end

Open in new window

0
 

Author Comment

by:dc_mo
ID: 34908086
works well, thank you.
0

Featured Post

Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 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