Recent

Author Topic: Subject: How to implement "MidPoint color" concept in gradient in photoshop, Usi  (Read 4892 times)

Sanem

  • Full Member
  • ***
  • Posts: 173
HI
I wanna implement the midpoint concept in Photoshop gradient using BGRA gradinet, as you can see in Screenshots attached (Left one is Photoshop gradinet for midpoint in its default position which is 50% and right one is the midpoint in 20% of the left color), the concept of midpoint in Photoshop is that we can change the location of the midpoint by dragging the icon closer to one color or the other. For example, when I drag it towards the left so it's closer to green stop. Notice the effect it's had on the gradient. With the midpoint now closer to green, I've shortened the transition area between green and the midpoint, and lengthened the transition between the midpoint and red.
it is not something i can implement by adding a middle point (a new color and a new position) in BGRA gradinet method, any idea how to implement this concept using BGRA gradinet methods?? Any idea??
(This question was raised first time in the thread:
http://forum.lazarus.freepascal.org/index.php/topic,31536.msg209491.html#msg209491
and I wanted to continue it in a new topic for gaining more idea or help and to be seen as a new topic generally.)

Any help appreciated prior
Regards

Here is my code for drawing the gradinet:

Code: Pascal  [Select][+][-]
  1.  
  2. unit Unit1;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
  10.   BGRABitmap, BGRABitmapTypes, BGRAGradients, BGRAGradientScanner, BGRAResample;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     procedure FormPaint(Sender: TObject);
  18.   private
  19.   public
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30. procedure TForm1.FormPaint(Sender: TObject);
  31. var
  32.   bmp: TBGRABitmap;
  33.   p1, p2: TPointF;
  34.   g: TBGRAMultiGradient;
  35.   gs: TBGRAGradientScanner;
  36. begin
  37.   bmp := TBGRABitmap.Create(Width, Height, clWhite);
  38.   p1 := PointF(0, Height / 2);
  39.   p2 := PointF(Width, Height / 2);
  40.   g := TBGRAMultiGradient.Create([BGRA(0, 0, 255), BGRA(0, 255, 0), BGRA(255, 0, 0)], [0, 0.5, 1], True, False);
  41.   g.InterpolationFunction := @g.CosineInterpolation;
  42.   gs := TBGRAGradientScanner.Create(g, gtLinear, p1, p2);
  43.   BGRASetGamma(1.45);
  44.   bmp.FillRectAntialias(0, 0, Width, Height, gs);
  45.   bmp.SaveToFile('Pics\BGRA_50%.png');
  46.   bmp.Draw(Canvas, 0, 0);
  47.   bmp.Free;
  48. end;
  49.  
  50. end.
  51.  
  52.  
« Last Edit: August 01, 2016, 10:23:00 am by simin_sh »

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Seems that you're making a photoshop clone or something like that! :)

Sanem

  • Full Member
  • ***
  • Posts: 173
Seems that you're making a photoshop clone or something like that! :)


Not really, I just was working on graphic related concepts ;) 

MaartenJB

  • Full Member
  • ***
  • Posts: 112
That's exactly what I needed, thanks for sharing it works great!

circular

  • Hero Member
  • *****
  • Posts: 4193
    • Personal webpage
To reproduce the wanted effect, (second gradient), you can do something like:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var
  3.   bmp: TBGRABitmap;
  4.   p1, p2: TPointF;
  5.   g: TBGRAMultiGradient;
  6.   gs: TBGRAGradientScanner;
  7. begin
  8.   BGRASetGamma(1.45);
  9.   bmp := TBGRABitmap.Create(Width, Height, clWhite);
  10.   p1 := PointF(0, Height / 2);
  11.   p2 := PointF(Width, Height / 2);
  12.   g := TBGRAMultiGradient.Create(
  13.     [BGRA(0, 0, 255),
  14.     BGRA(0, 255, 0),
  15.     MergeBGRAWithGammaCorrection(BGRA(0, 255, 0), 1, BGRA(255, 0, 0), 1),
  16.     BGRA(255, 0, 0)],
  17.     [0, 0.5, 0.6, 1], True);
  18.   g.InterpolationFunction := @g.CosineInterpolation;
  19.   gs := TBGRAGradientScanner.Create(g, gtLinear, p1, p2);
  20.   bmp.FillRectAntialias(0, 0, Width, Height, gs);
  21.   bmp.SaveToFile('BGRA_50%.png');
  22.   bmp.Draw(Canvas, 0, 0);
  23.   bmp.Free;
  24. end;
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018