Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Crop with GR32 - need better interface (https://www.delphipraxis.net/154942-crop-gr32-need-better-interface.html)

WojTec 2. Okt 2010 12:51

Crop with GR32 - need better interface
 
Hello guys,

I know some of you know GR32, could you help me?

So, I need better interface for cropping function - now I'm using TRubberbandLayer and it working, but looking not to nice. I want to make area outside this 'frame' in specific color and opacity, eg. 50% black, like in PS. Do you understand what I mean? How can I do this?

Namenloser 2. Okt 2010 16:03

AW: Crop with GR32 - need better interface
 
So, you want to have everything darkened except for a specific rectangular area, is that correct?
I'd just fetch the pixel pointer of the top left pixel and then iterate over all the pixels, checking if they are in the rectangle and darken them where applicable.

The following was supposed to be pseudo code but turned out to be actual code... it's untested as I just wrote it here in the browser, so it most likely won't compile without a few adjustments.
Delphi-Quellcode:
procedure HighlightCropRect(Bmp32: TBitmap32; CropRect: TRect);
var
  Ptr: PColor32;
  LastPtr: PColor32;
  X,Y: Integer;
begin
  // Get pointers of first and last pixel
  Ptr := Bmp32.PixelPtr[0,0];
  LastPtr := Bmp32.PixelPtr[Bmp32.Width-1, Bmp32.Height-1];
  // Init Pixel coordinates
  X := 0;
  Y := 0;

  // Iterate over all pixels
  // (We need to do a typecast here because we can't compare pointers in Delphi)
  while Integer(Ptr) < Integer(LastPtr) do
  begin
    // Check if pixel is outside of crop rect
    if (X < CropRect.Left) or (X > CropRect.Right) or
       (Y < CropRect.Top) or (Y > CropRect.Bottom) then
    begin
      // Darken pixel by 50%
      Ptr^ := Lighten(Ptr^, -127);
    end;

    // Move to next pixel
    inc(Ptr);
    inc(X);
    // Reached end of scanline?
    if X >= Bmp32.Width then
    begin
      X := 0;
      inc(Y);
    end;
  end;

end;

WojTec 3. Okt 2010 20:46

Re: Crop with GR32 - need better interface
 
Liste der Anhänge anzeigen (Anzahl: 1)
Yes, you are correct :) But I mean something like this on picture. This is screen from PS - I already have only this tool frame (TRubberbandLayer) and I don't know how to make shadow outside selected area (lines inside are nice too) - maybe some additional layer that have TRubberbandLayer as child? - but how?

Namenloser 3. Okt 2010 20:56

AW: Crop with GR32 - need better interface
 
I have no experience with gr32 layers. You'll have to find out how to adapt my code to the layers framework yourself.

Medium 3. Okt 2010 23:41

AW: Crop with GR32 - need better interface
 
Totally different idea: You already have a method to draw the bright rectangle, right? Then you also have all four corner coordinates of that rectangle. How about adding 8 more entirely black layers with 50% opacity, so that they cover everything that isn't inside the selection?
For the frame... well, just draw it in yet another additional layer :)

On a side note: I like your sample image ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:16 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz