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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 how to slice a picture in to the equal parts?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

guja

3 Posts

Posted - Nov 21 2018 :  09:52:47  Show Profile  Reply
how can i slice a picture in to the several equal parts (eg. 8x10) and save them to the files?

xequte

39052 Posts

Posted - Nov 21 2018 :  16:03:14  Show Profile  Reply
Hi

It would be something like:

// Method that takes an image, splits it into multiple cells and saves each cell to file
procedure SplitImage(Bitmap: TIEBitmap; cols, rows: integer; DestFolder: string);
var
  cellWidth, cellHeight: Double;
  x,y : Integer;
  outBmp: TIEBitmap;
begin
  cellWidth := Bitmap.Width / cols;
  cellHeight := Bitmap.Height / rows;

  outBmp := TIEBitmap.Create;
  outBmp.Allocate( Round( cellWidth ), Round( cellHeight ));

  for x := 0 to cols do
    for y := 0 to rows do
    begin
      Bitmap.CopyRectTo( outBmp,
                         Round( cellWidth * x ), Round( cellHeight * y ),
                         0, 0,
                         Round( cellWidth ), Round( cellHeight ));
      outBmp.Write( IncludeTrailingBackSlash( DestFolder ) + IntToStr( x ) + '_' + IntToStr( y ) + '.bmp' );
    end;

  outBmp.Free;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

guja

3 Posts

Posted - Nov 22 2018 :  03:53:00  Show Profile  Reply
Thank you!
1. Is this code thread-safe?
2. What is the fastest way to compare two TIEBitmap and determine whether they are the same?
3. Is there way to save outBmp as JPEG to the Stream (without headers)? i use ImageEn 5.2.0
Go to Top of Page

wesleybobato

Brazil
367 Posts

Posted - Nov 22 2018 :  09:56:39  Show Profile  Reply
Hi guja

In Delphi all class parameters or records are pointers.
This means that any changes made to the parameter change the origin.

Example

procedure Image_NotThreadSafe(Image: TImage);
begin
  //It does not matter if the parameter is Param, Const or Var
  //Because I'm passing an object class.

  Image.Picture.Bitmap.SetSize( 0, 0 );
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.LoadFromFile( 'Tulips.jpg' );
  Image_NotThreadSafe( Image1 );
end;


Note that Bitmap.CopyRectTo, makes only one copy of a region, and does not write or change.
Then it's Thread Safe.

You can write in a bitmap using Thread Safe I do this but one must be careful not to try to write in a region that does not exist!

I recommend reading this page has several examples of how to write to a Bitmap using PPL.

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Using_the_Parallel_Programming_Library

2. Image Comparison Compare the content of two images side-by-side
https://www.imageen.com/files/demos/run/Display/ImageComp/ImageComp.exe

3. Save without headers? how will you identify after that the Stream is a JPEG or an image file?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: