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
 Cropping Fail
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

skippix

USA
68 Posts

Posted - Jun 28 2014 :  04:23:53  Show Profile  Reply
I have modeled off the cropping demo, but am not getting the results I want.
This is what I draw:


And this is what I get:


Using this code:
procedure TctHelpImageInventoryBuilder.btnSaveImageFileClick(Sender: TObject);
const
  JPEG_FILTER_INDEX = 3;   // 5 for JPEG types
var
  rc: TRect;
  destFile: string;
begin
  destFile := ctutils.GenUniqueFilename(sourceFile)
  if destFile <> '' then
    begin
    // get cut rectangle
      with ImageEnView1 do
        rc := Rect(SelX1, SelY1, SelX2, SelY2);
    // apply lossless cut and save
      JpegLosslessTransform(sourceFile, destFile, jtCut, false, jcCopyAll, rc);
      if (ckbDeselectOnSave.Checked) then
        ImageEnView1.DeSelect;
      Talk (lblTalk, 'File saved to: ' + destFile);
    end
  else
    Talk (lblTalk, 'File not saved');
end;


What am I missing? I really need this to be WYSIWYG.

Thanks!

w2m

USA
1990 Posts

Posted - Jun 28 2014 :  09:36:47  Show Profile  Reply
If ImageEnView.SelectionBase property is set to iesbClientArea you have to convert XY values. Without converting the simplest thing to do is to set ImageEnView.SelectionBase to iesbBitmap.

If SelectionBase is iesbClientArea (default) then all coordinates depend upon the actual zoom and window view/scrolling (i.e. pixels on screen). Otherwise, if SelectionBase is iesbBitmap, then all coordinates refer to bitmap pixels.

To convert XY values see:
- XBmp2Scr
- XScr2Bmp
- YBmp2Scr
- YScr2Bmp

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

skippix

USA
68 Posts

Posted - Jun 29 2014 :  12:54:44  Show Profile  Reply
Thanks! I'll give it a shot and let you know how it works out, or if I need further assistance.
Go to Top of Page

skippix

USA
68 Posts

Posted - Jul 01 2014 :  17:04:04  Show Profile  Reply
I couldn't get it to work and wasn't able to readily find any examples for using XY values for cropping.

Instead, I opted for the easy way out: using another ImageEnView and modeling off the cropping done in the PhotoEn demo. Basically, assign the selection to the second component, then save.


  ieCropper := TImageEnView.Create(nil);
  ImageEnView1.AssignSelTo(ieCropper);
  ieCropper.IO.SaveToFile(destFile);
  FreeAndNil(ieCropper);


No fuss, no muss, and completely WYSIWYG :D
Go to Top of Page

xequte

39053 Posts

Posted - Jul 01 2014 :  19:45:41  Show Profile  Reply
Alternatively:

  SelBitmap := TIEBitmap.Create;
  ImageEnView1.CopySelectionToIEBitmap(SelBitmap);
  SelBitmap.Write(destFile);
  FreeAndNil(SelBitmap);

(Slightly less overhead)

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: