ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Blurring "outside area" when pasting image

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
HeartWare Posted - Mar 01 2022 : 03:27:09
If I have one TBitMap of 100x150 and one TBitMap of 100x100 and I want this 100x100 bitmap centered in the middle of the 100x150 bitmap, but with the 100x25 areas on top and bottom be a "blurred" extension of the pasted image (like you can do with TImageEnView BackgroundStyle=iebsBlurredImage when the image doesn't fill the entire ImageView area) - how do I programmatically do this?

The code should also handle the situation where the blurring is on the sides, as well as on all four sides...
2   L A T E S T    R E P L I E S    (Newest First)
HeartWare Posted - Mar 02 2022 : 01:23:18
Excellent. Will try it out immediately.

Thank you...
xequte Posted - Mar 01 2022 : 16:21:44
Yes, you can do it as follows:

// CREATE BITMAP WITH BLURRED IMAGE FILLING NON-IMAGE AREA
// DestBmp: Output image for result
// BackgroundBmp: Image to use as background (must be valid)
// ImageBmp: Image to draw centered (can be same as BackgroundBmp, or can be NIL)
// Width, Height: Size to make DestBmp
// BlurRadius: How much to blur image (Default is 8, 0 for no blur)
// BackgroundOpacity: If less than 1.0, the background is drawn semi-opaque (with BackgroundColor visible)
procedure StretchDrawWithBlur(DestBmp, BackgroundBmp, ImageBmp: TIEBitmap; 
                              Width, Height: Integer; 
                              BlurRadius: Integer = 8; 
                              BackgroundOpacity: Double = 0.75; BackgroundColor: TColor = clBlack);
var
  aRect: TRect;
  DestRect : TIERectangle;
begin
  // Allocate and size
  if not assigned( DestBmp ) then
    DestBmp := TIEBitmap.create;
  DestBmp.Allocate( Width, Height );

  // Fill background color if needed
  if BackgroundOpacity < 1.0 then
    DestBmp.Fill( BackgroundColor );

  // Scale draw the background to fill entire image area
  aRect := GetImageRectWithinArea( BackgroundBmp.Width, BackgroundBmp.Height, DestBmp.Width, DestBmp.Height,
                                   0, 0, True, True, True, True, 0,
                                   _fmFillRect_WithOverlap );
  DestRect := IERectangle( aRect );
  BackgroundBmp.RenderToTIEBitmapEx( DestBmp, DestRect.X, DestRect.Y, DestRect.Width, DestRect.Height,
                                     0, 0, BackgroundBmp.Width, BackgroundBmp.Height,
                                     True, 255, rfNone, ielNormal, BackgroundOpacity );

  // Blur the background
  // IEGBlur() is the same as calling  TImageEnProc.Blur()
  if BlurRadius > 0 then
    IEGBlur( DestBmp, BlurRadius, nil, nil );

  // Draw our image
  if ImageBmp <> nil then
  begin
    aRect := GetImageRectWithinArea( ImageBmp.Width, ImageBmp.Height, DestBmp.Width, DestBmp.Height );
    DestRect := IERectangle( aRect );
    ImageBmp.RenderToTIEBitmapEx( DestBmp, DestRect.X, DestRect.Y, DestRect.Width, DestRect.Height,
                                  0, 0, ImageBmp.Width, ImageBmp.Height,
                                  True, 255, rfNone, ielNormal, 1.0 );
  end;
end;


// EXAMPLE USAGE
procedure TForm1.Button1Click(Sender: TObject);
var
  bmpIn, bmpOut: TIEBitmap;
begin
  bmpIn := TIEBitmap.Create;
  bmpOut := TIEBitmap.Create();
  try
    bmpIn.Read( 'D:\im.jpg' );
    StretchDrawWithBlur( bmpOut, bmpIn, bmpIn, 800, 600, 8, 0.75, clWhite );

    ImageEnView1.Assign( bmpOut );
  finally
    bmpIn.Free;
    bmpOut.Free;
  end;
end;




Nigel
Xequte Software
www.imageen.com