Solved

Display RGB channels of image

Posted on 2011-02-16
4
451 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 500 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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