AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Crop with GR32 - need better interface
Thema durchsuchen
Ansicht
Themen-Optionen

Crop with GR32 - need better interface

Ein Thema von WojTec · begonnen am 2. Okt 2010 · letzter Beitrag vom 3. Okt 2010
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

Crop with GR32 - need better interface

  Alt 2. Okt 2010, 12:51
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?
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#2

AW: Crop with GR32 - need better interface

  Alt 2. Okt 2010, 16:03
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;
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#3

Re: Crop with GR32 - need better interface

  Alt 3. Okt 2010, 20:46
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?
Miniaturansicht angehängter Grafiken
bez%A0tytu-u.png  

Geändert von WojTec ( 3. Okt 2010 um 20:49 Uhr)
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#4

AW: Crop with GR32 - need better interface

  Alt 3. Okt 2010, 20:56
I have no experience with gr32 layers. You'll have to find out how to adapt my code to the layers framework yourself.
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#5

AW: Crop with GR32 - need better interface

  Alt 3. Okt 2010, 23:41
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
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:28 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz