Learn more about GDI + [93]: tgpimage (13)-adjust the three primary colors of red, green, and blue and the transparency of the image

Source: Internet
Author: User
In this example:


Code file:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, comctrls; Type tform1 = Class (tform) trackbar1: ttrackbar; trackbar2: ttrackbar; trackbar3: ttrackbar; trackbar4: ttrackbar; label1: tlabel; label2: tlabel; label3: tlabel; label4: tlabel; Procedure alert (Sender: tobject); Procedure alert (Sender: tobject); Procedure future (Sender: tobject); Procedure trackbar1change (Sender: tobject); Procedure future (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; var IMG: tgpimage; var colormatrix: tcolormatrix = (1.0, 0.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0 )); procedure tform1.formcreate (Sender: tobject); begin IMG: = tgpimage. create ('C: \ temp \ test.png '); {This is a specially crafted color test image} trackbar1.height: = 23; trackbar1.showselrange: = false; trackbar1.max: = 100; trackbar1.position: = trackbar1.max; trackbar2.height: = 23; trackbar2.showselrange: = false; trackbar2.max: = 100; trackbar2.position: = trackbar2.max; trackbar3.height: = 23; Category: = false; trackbar3.max: = 100; trackbar3.position: = trackbar3.max; trackbar4.height: = 23; trackbar4.showselrange: = false; trackbar4.max: = 100; trackbar4.position: = trackbar4.max; doublebuffered: = true; end; procedure invoke (Sender: tobject ); begin IMG. free; end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; imageattributes: tgpimageattributes; begin G: = tgpgraphics. create (canvas. handle); imageattributes: = tgpimageattributes. create; colormatrix [100]: = trackbar1.position/100; {adjusted red} colormatrix [100]: = trackbar2.position/; {adjusted green} colormatrix []: = trackbar3.position; {adjust blue} colormatrix [3, 3]: = trackbar4.position/100; {adjust transparency} imageattributes. setcolormatrix (colormatrix); G. drawimage (IMG, {image to be drawn} makerect (10, 10, IMG. getwidth, IMG. getheight), {the image will be scaled down to fit this rectangle} 0, 0, {drawing position} IMG. getwidth, IMG. getheight, {size} unitpixel, {unit} imageattributes {image attribute}); imageattributes. free; G. free; end; Procedure tform1.trackbar1change (Sender: tobject); begin repaint; end; Procedure prepare (Sender: tobject); begin repaint; end; Procedure tform1.trackbar3change (Sender: tobject ); begin repaint; end; Procedure tform1.trackbar4change (Sender: tobject); begin repaint; end.
 

Form file:

object Form1: TForm1  Left = 0  Top = 0  Caption = 'Form1'  ClientHeight = 259  ClientWidth = 219  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  Position = poDesktopCenter  OnCreate = FormCreate  OnDestroy = FormDestroy  OnPaint = FormPaint  PixelsPerInch = 96  TextHeight = 13  object Label1: TLabel    Left = 23    Top = 160    Width = 24    Height = 13    Caption = #32418#33394  end  object Label2: TLabel    Left = 23    Top = 184    Width = 24    Height = 13    Caption = #32511#33394  end  object Label3: TLabel    Left = 23    Top = 206    Width = 24    Height = 13    Caption = #34013#33394  end  object Label4: TLabel    Left = 11    Top = 230    Width = 36    Height = 13    Caption = #36879#26126#24230  end  object TrackBar1: TTrackBar    Left = 48    Top = 157    Width = 164    Height = 45    TabOrder = 0    OnChange = TrackBar1Change  end  object TrackBar2: TTrackBar    Left = 48    Top = 179    Width = 164    Height = 45    TabOrder = 1    OnChange = TrackBar2Change  end  object TrackBar3: TTrackBar    Left = 48    Top = 201    Width = 163    Height = 45    TabOrder = 2    OnChange = TrackBar3Change  end  object TrackBar4: TTrackBar    Left = 48    Top = 224    Width = 163    Height = 45    TabOrder = 3    OnChange = TrackBar4Change  endend
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.