Recent

Author Topic: [SOLVED] Splitting an image  (Read 7734 times)

madref

  • Hero Member
  • *****
  • Posts: 987
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[SOLVED] Splitting an image
« on: April 24, 2024, 08:05:04 am »
I have an image (TImage) that I want to split Ito two images so that I can put them under each other.
The Image is 365 pixel wide and I want to split into 165 and 200 pixels


How can I do that?
« Last Edit: May 16, 2024, 07:21:27 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Sonoma

paule32

  • Full Member
  • ***
  • Posts: 233
Re: splitting an image
« Reply #1 on: April 24, 2024, 08:20:33 am »
simply:
- use two separate TImage's like a map, or:
- use a tile map (a single file, with tiles in square with same width/height

good luck

madref

  • Hero Member
  • *****
  • Posts: 987
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: splitting an image
« Reply #2 on: April 24, 2024, 08:55:22 am »
Can you explain it a bit more?
Because I don't understand what you mean
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Sonoma

paule32

  • Full Member
  • ***
  • Posts: 233
Re: splitting an image
« Reply #3 on: April 24, 2024, 09:13:32 am »
- you can use multiple images, that you can "TImage.LoadFromFile"
=> Then you have more loading time
=> Then you can store the images on Form's - but they overlapped eventually
=> Then you can exchange the images from each load time/update of your software
=> Then you can load/un-load the images which means, allocate/de-allocate memory

- you can use one or multiple tile images, load it per LoadFromFile, store it into a background Canvas/Handle, and BitBlt (copy) the background data into the foreground (enabled/viewing view port on TForm or other TComponent)
=> Then you can gzip/zlib (compress) these file/s to save storage space
=> Then you can copy in-Memory data into background Canvas/foreground Canvas in time faster than if you use TImage.LoadFromFile
=> Then you need a little bit lesser memory
=> Then you can hold one copy of the image in the memory
=> Eventually, you need more memory.

On tile images, you have to know the exact position of the tiles - when not, then you have eventually image garbage on the device where you display/print the image's/tile's.
« Last Edit: April 24, 2024, 09:15:22 am by paule32 »

madref

  • Hero Member
  • *****
  • Posts: 987
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: splitting an image
« Reply #4 on: April 24, 2024, 09:18:14 am »
I don't need to save or do anything to the image.
I just want to split the image in two parts.
The image contains text (like "Text Example") that I want to split
And I want to display it as:


Text
Example
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Sonoma

paule32

  • Full Member
  • ***
  • Posts: 233
Re: splitting an image
« Reply #5 on: April 24, 2024, 09:23:22 am »
I don't write anything about "saving".

You maybe over read it:
the principle is:
- load a file (that can be done with "LoadFromFile")
- and BitBlt (copy a view port of the memory region of the image) to a destination Canvas

This Canvas can be any "displayable" device (screen, printer, or memory)

TRon

  • Hero Member
  • *****
  • Posts: 2660
Re: splitting an image
« Reply #6 on: April 24, 2024, 09:40:23 am »
@madref:
1. Do you write the text yourself with code into the image ?
2. Are you sure you want to have two separate TImage components in return ? (resulting in a total of 3 TImage components on your form)
3. in case 2 applies do these two other TImage components already exist
4. in case answer to 2 is no then where do you want the resulting "splitted" images to be stored ?
5. Is the splitting process itself a manual step, e.g. you have to click a button or should it be done when something specific happens on the form ?

madref

  • Hero Member
  • *****
  • Posts: 987
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: splitting an image
« Reply #7 on: April 24, 2024, 10:18:58 am »
the image is loaded like this from a TImageList. It is depended on a color:
Code: Pascal  [Select][+][-]
  1.   case KleurPop of
  2.     Oranje : ImageList_Divisie.GetBitmap(0,Image_Divisie.Picture.Bitmap); // Oranje
  3.     Rood   : ImageList_Divisie.GetBitmap(1,Image_Divisie.Picture.Bitmap); // Rood
  4.     Blauw  : ImageList_Divisie.GetBitmap(2,Image_Divisie.Picture.Bitmap); // Blauw
  5.     Groen  : ImageList_Divisie.GetBitmap(3,Image_Divisie.Picture.Bitmap); // Groen
  6.     Paars  : ImageList_Divisie.GetBitmap(4,Image_Divisie.Picture.Bitmap); // Paars
  7.     Geel   : ImageList_Divisie.GetBitmap(5,Image_Divisie.Picture.Bitmap); // Geel
  8.     Zwart  : ImageList_Divisie.GetBitmap(6,Image_Divisie.Picture.Bitmap); // Zwart
  9.   end;  // case
the idea was to, if possible, split this image into 2 images. So the idea is to have 2 TImage placeholders
1 is holding the left part of the image and the other 1 is holding the right part of this image.
i have added an example image
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Sonoma

TRon

  • Hero Member
  • *****
  • Posts: 2660
Re: splitting an image
« Reply #8 on: April 24, 2024, 10:34:19 am »
the image is loaded like this from a TImageList. It is depended on a color:
That answers at least one of my questions ....  :P

Ah well, let's see how far you are able to get with the following (you would have to adjust to meet your specific requirements).

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   sameArea: TRect;
  4.   srcRect: TRect;
  5.   dstRect: TRect;
  6. begin
  7.   // split original image into two separated ones
  8.  
  9.   // left part of original image has the exact same rectangle coordinates as
  10.   // the destination image and is 165 pixels width.
  11.   sameArea    := Bounds(0,0,165, Image1.Height);
  12.   // Copy rectangle area from image1 (leftmost part) to image2
  13.   Image2.Canvas.CopyRect(sameArea, Image1.Canvas, sameArea);
  14.  
  15.   // right part of original image is located 165 pixels from the left
  16.   srcRect := Bounds(165, Image1.Canvas.ClipRect.Top, Image1.Canvas.ClipRect.Width-165, Image1.Canvas.ClipRect.Height);
  17.   // copied image starts at topleft of canvas and is 200 pixels width
  18.   dstRect := Bounds(  0,                          0,                              200, Image1.Canvas.ClipRect.Height);
  19.   // copy rectangel from image1 (rightmost part) to image3
  20.   Image3.Canvas.CopyRect(dstRect, Image1.Canvas, srcRect);
  21. end;
  22.  
« Last Edit: April 24, 2024, 10:41:12 am by TRon »

Dzandaa

  • Sr. Member
  • ****
  • Posts: 272
  • From C# to Lazarus
Re: splitting an image
« Reply #9 on: April 24, 2024, 11:15:40 am »
Hi,

You cant try this skeleton (using BGRABitmap)

B->
Dzandaa

madref

  • Hero Member
  • *****
  • Posts: 987
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: splitting an image
« Reply #10 on: April 24, 2024, 04:39:31 pm »
@Dzandaa


You use
Code: Pascal  [Select][+][-]
  1.                 Picture:= TBGRABitmap.Create;
  2.                 Picture.LoadFromFile(DOpenPicture.FileName);
  3.  
to load the picture.


But how do I do this from a TImageList
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Sonoma

Thaddy

  • Hero Member
  • *****
  • Posts: 14575
  • Sensorship about opinions does not belong here.
Re: splitting an image
« Reply #11 on: April 24, 2024, 04:52:43 pm »
LoadFromStream/SaveToStream?
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

Dzandaa

  • Sr. Member
  • ****
  • Posts: 272
  • From C# to Lazarus
Re: splitting an image
« Reply #12 on: April 24, 2024, 06:40:45 pm »
Hi
@madref, there is a TBGRAImageList in the BGRABitmap distribution, but I didn't try it yet...

https://wiki.lazarus.freepascal.org/BGRAControls#TBGRAImageList

B->
Dzandaa

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2216
  • Fifty shades of code.
    • Delphi & FreePascal
Re: splitting an image
« Reply #13 on: April 24, 2024, 07:07:21 pm »
Image2 will contain the left half and Image3 the right half from the original imagelist picture.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   LBMP: TBitmap;
  4.   HalfBMP: TBitmap;
  5.   X: Integer;
  6. begin
  7.   LBMP := TBitmap.Create;
  8.   try
  9.     HalfBMP := TBitmap.Create;
  10.     try
  11.       ImageList1.GetBitmap(0, LBMP); // here i do put the image from imagelist index 0 into LBMP
  12.       X := LBMP.Width div 2; // at that position I do split the image
  13.       HalfBMP.Width := X;
  14.       HalfBMP.Height := LBMP.Height;
  15.       // left half:
  16.       HalfBMP.Canvas.CopyRect(Rect(0, 0, X, LBMP.Height), LBMP.Canvas, Rect(0, 0, X, LBMP.Height));
  17.       Image2.Picture.Bitmap.Assign(HalfBMP);
  18.       // right half:
  19.       HalfBMP.Canvas.CopyRect(Rect(0, 0, X, LBMP.Height), LBMP.Canvas, Rect(X, 0, LBMP.Width, LBMP.Height));
  20.       Image3.Picture.Bitmap.Assign(HalfBMP);
  21.     finally
  22.       HalfBMP.Free;
  23.     end;
  24.   finally
  25.     LBMP.Free;
  26.   end;
  27. end;
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

madref

  • Hero Member
  • *****
  • Posts: 987
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: splitting an image
« Reply #14 on: April 25, 2024, 11:33:37 am »
How to compensate for the black?
It should be transparent.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Sonoma

 

TinyPortal © 2005-2018