Results 1 to 20 of 20

Thread: Image crop with GDI+

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,897

    Re: Image crop

    If you're using the code I provide to set the crop rect, there's no need to involve GDI+ at all. Stay with RC6/Cairo and use the CropSurface method to get a new surface at the required coords and save it to disk. Something like:

    Code:
    mo_SrfOrig.CropSurface(mt_SelRect.Left, _
                                        mt_SelRect.Top, _
                                        mt_SelRect.Right - mt_SelRect.Left, _
                                        mt_SelRect.Bottom - mt_SelRect.Top).WriteContentToJpgFile App.Path & "\cropped.jpg"

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2011
    Posts
    809

    Re: Image crop

    Quote Originally Posted by jpbro View Post
    If you're using the code I provide to set the crop rect, there's no need to involve GDI+ at all. Stay with RC6/Cairo and use the CropSurface method to get a new surface at the required coords and save it to disk. Something like:

    Code:
    mo_SrfOrig.CropSurface(mt_SelRect.Left, _
                                        mt_SelRect.Top, _
                                        mt_SelRect.Right - mt_SelRect.Left, _
                                        mt_SelRect.Bottom - mt_SelRect.Top).WriteContentToJpgFile App.Path & "\cropped.jpg"
    tks. I already have a working model using GDI+ to save and view images and works well.

    What i am looking to do is have a list of images. then i can right click each one and the crop form appears. I select the portion i want from Left image. On right i have the cropped image from the original file
    showing. if i am happy then click ok. the coordinates are then saved for processing.

    Once i am ready, i can process all files and either resize the whole image if not cropped or if an image is cropped resize the cropped image.

    but its always worth knowing another method.

    are there other save as methods like WriteContentToJpgFile, can it save to PNG, Tif,Gif,BMP etc or is it just that one

    Just tried .WriteContentToGifFile , .WriteContentToBmpFile , .WriteContentToTifFile but these dont work.

    tks
    Last edited by k_zeon; Apr 19th, 2025 at 05:08 AM.

  3. #3
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,897

    Re: Image crop

    Quote Originally Posted by k_zeon View Post
    are there other save as methods like WriteContentToJpgFile, can it save to PNG, Tif,Gif,BMP etc or is it just that one

    Just tried .WriteContentToGifFile , .WriteContentToBmpFile , .WriteContentToTifFile but these dont work.
    If Intellisense isn't working in your IDE, I recommend trying to get that fixed - programming without it can be pretty painful (especially with a new library). With Intellisense working & enabled you will see the following .WriteContent* methods:

    • WriteContentToJpgByteArray
    • WriteContentToJpgFile
    • WriteContentToPdfByteArray
    • WriteContentToPdfFile
    • WriteContentToPngByteArray
    • WriteContentToPngFile
    • WriteContentToSvgByteArray
    • WriteContentToSvgFile


    The only conspicuously missing common Windows image format is BMP, but there is also a Picture property that returns an StdPicture so you can use the built-in VB6 SavePicture method to save a BMP file from a Cairo surface. For all other formats, you would need to use a different library to process the raw data (possibly via BindToArray/BindToArrayLong methods)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width