logo
Tags down

shadow

Make darker each pixel in a TImage


By : Daniel Francis
Date : October 14 2020, 02:15 PM
it should still fix some issue Just use ScanLine of your PNG-image to make it darker before assign it to TImagecomponent. It should be faster then convert TBitmap from TImage to PNG, perform actions and convert it back to TBitmap and assign it to TImage component again. Also, once you assigned PNG to TBitmap there is no way to get partial transparency of PNG back. At least, all my trying in past weren't successful, that's why I prefer to store PNG-files inside my small programs and change (sizing, blending etc.) their copy during run-time.
I changed your source code to exclude operations with floating point. It was replaced with MulDiv function.
code :
function DarkerColor(thisColor: TColor; thePercent: Byte): TColor;
var
  (* a TColor is made out of Red, Green and blue *)
  cRed,
  cGreen,
  cBlue: Byte;
begin
  (* get them individually *)
  cRed := GetRValue(thisColor);
  cGreen := GetGValue(thisColor);
  cBlue := GetBValue(thisColor);

  (* make them darker thePercent *)
  cRed := MulDiv(cRed, thePercent, 100);
  cGreen := MulDiv(cGreen, thePercent, 100);
  cBlue := MulDiv(cBlue, thePercent, 100);

  (* return them as TColor *)
  Result := RGB(cRed, cGreen, cBlue);
end;  
procedure MakePNGDarker(APNGInOut: TPNGImage; AValue: Integer);
type
  TRGBArray = Array [0..65535 - 1] of WinAPI.Windows.tagRGBTRIPLE;
  PRGBArray = ^TRGBArray;
var
  RowInOut: PRGBArray;
  SourceColor: TColor;
  ResultColor: TColor;
  X: Integer;
  Y: Integer;
begin
  if not Assigned(APNGInOut) or (AValue < 0) then
    Exit;

  for Y:=0 to APNGInOut.Height - 1 do
    begin
      RowInOut := APNGInOut.ScanLine[Y];
      for X:=0 to APNGInOut.Width - 1 do
        begin
          SourceColor := RGB(RowInOut[X].rgbtRed, RowInOut[X].rgbtGreen, RowInOut[X].rgbtBlue);
          ResultColor := DarkerColor(SourceColor, AValue);

          RowInOut[X].rgbtRed := GetRValue(ResultColor);
          RowInOut[X].rgbtGreen := GetGValue(ResultColor);
          RowInOut[X].rgbtBlue := GetBValue(ResultColor);
        end;
    end;
end;  


Share : facebook icon twitter icon

How to make a water effect on TImage or anything?


By : Igor Mileusnic
Date : March 29 2020, 07:55 AM
I hope this helps . See Leonel Togniolli's "Water Effects" at efg's lab.

How do I make the action sheet make the surrounding view darker when it's called?


By : Yuhan Duan
Date : March 29 2020, 07:55 AM
will be helpful for those in need The action sheet naturally greys out the background view a little bit, but it isn't really noticeable. I want to make it much darker. , You may try something like this:
code :
@property (nonatomic, strong) UIView *shadowView; 

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
    if (!self.shadowView)
    {
        self.shadowView = [[UIView alloc]initWithFrame:self.view.bounds];
        self.shadowView.backgroundColor = [UIColor colorWithRed:(42.0/255.0) green:(42.0/255.0) blue:(42.0/255.0) alpha:1.0];
        self.shadowView.alpha = 0.7;
        [self.view addSubview:self.shadowView];
    }
    else
    {
        self.shadowView.alpha = 0.7;
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    self.shadowView.alpha = 0.0;
}

Delphi 7 - Assigning a TImage to array of TImage


By : samkral
Date : March 29 2020, 07:55 AM
hope this fix your issue I suggest you use a TImageList to store your images and display those on screen using TImages as needed.
Make sure the Images are transparent. You can duplicate images in the ImageList if you don't want to rotate them in code.
code :
procedure TForm1.CreateForm(Sender: TObject); 
begin
  //Init array here, no action needed, because all object members are zero to start with.
end;

procedure TForm1.AddShip(Location: TPoint; ImageIndex: integer);
var
  x,y: integer;
  NewImage: TImage;
  Bitmap: TBitmap;
begin
  x:= Location.x; y:= Location.y;
  if ImageArray[X, Y] = nil then begin
    NewImage:= TImage.Create(Self);
    NewImage.Parent:= Panel1;
    NewImage.Transparent:= true;
    NewImage.Left:= x * GridSize;
    NewImage.Top:= y * GridSize;
    ImageArray[x,y]:= NewImage;
  end;
  if ImageList1.GetBitmap(ImageIndex, Bitmap) then begin
    ImageArray[x,y].Picture.Assign(Bitmap);
  end else raise Exception.Create(Format('Cannot find an image with index %d in %s',[ImageIndex,'ImageList1']));
end;
TGridRect = record
  shiptype: TShiptype;
  orientation: THorizontalOrVertical;
  shipsection: integer;
  HiddenFromEnemy: boolean;
end;

TGrid = array[0..9,0..9] of TGridRect;
procedure TForm1.Paint(Sender: TObject);
var
  GridRect: TGridRect;
  Bitmap: TBitmap;
  ImageIndex: integer;
begin
  for x:= 0 to 9 do begin
    for y:= 0 to 9 do begin
      GridRect:= Grid[x,y];
      ImageIndex:= Ord(GridRect.ShipType) * NumberOfParts 
                   + GridRect.ShipSection * (Ord(GridRect.Orientation)+1);
      Bitmap:= TBitmap.Create;
      try
        ImageList1.GetBitmap(ImageIndex, Bitmap);
        Panel1.Canvas.Draw(x*GridSize, y*GridSize, Bitmap);
      finally 
        Bitmap.Free;
      end;
    end; {for y}
  end; {for x}

Delphi TImage: How do I display images that are larger than the TImage component they are being loaded in or assigned to


By : Namide
Date : March 29 2020, 07:55 AM
it helps some times Since you are not getting an error when loading the JPEG image, I suspect the problem may be in the conversion from TJPEGImage to TBitmap. Unless you are going to be manipulating the image pixels, you don't need the conversion at all, you can assign the original TJPEGImage directly to the TImage. The VCL's TPicture class uses derived TGraphic classes so it can display images in their native formats, you should utilize that feature, eg:
code :
procedure TForm1.btnBrowseClick(Sender: TObject);
var
  jpg: TJPEGImage;
  bmp: TBitmap;
begin
  OpenPicturedialog1.InitialDir := FindImageFolder(true);
  if OpenPictureDialog1.Execute then
  begin
    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);

    if Image1.Picture.Graphic is TJPEGImage then
    begin
      if TJPEGImage(Image1.Picture.Graphic).Grayscale then
      begin
        Image2.Picture.Assign(Image1.Picture.Graphic);
      end else
      begin
        jpg := TJPEGImage.Create;
        try
          jpg.Assign(Image1.Picture.Graphic);
          jpg.Grayscale := True;
          Image2.Picture.Assign(jpg);
        finally
          jpg.Free;
        end;
      end;
    end else
    begin
      bmp := TBitmap.Create;
      try
        bmp.PixelFormat := pf32bit;
        bmp.Assign(Image1.Picture.Graphic);
        ...
        Image2.Picture.Assign(bmp);
      finally
        bmp.Free;
      end;
    end;
  end;
end;

QColor Hot to get darker image (array of pixels) in qt creator (using function darker)?


By : chensi
Date : March 29 2020, 07:55 AM
should help you out darker() is a member function, you need to invoke it from a color instance:
code :
QColor color = someColor.darker(300);
shadow
Privacy Policy - Terms - Contact Us © voile276.org