Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Display RGB channels of image

Posted on 2011-02-16
4
Medium Priority
?
458 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
  • 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

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

783 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