Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Crop Function showing no result

Crop Function showing no result

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thescouse
    wrote on last edited by
    #1

    Hi everyone.
    I wrote a function to crop an image. The function is as follows:
    void ImageViewer::crop()
    { QString fileName=QFileDialog::getSaveFileName(this,tr("Save File"),QDir::currentPath());
    QImage image(fileName);
    QImage copy ;
    copy = image.copy( 0, 0, 128, 128);
    }
    The program runs without error. But when I try to crop an image, it shows no change and just prompts me to save it, that's all...no change.
    Can anyone tell me where the problem is
    Thanks

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Please code tags to display the code. This way it will be easier for others to understand your code.

      From your code what i understand is,
      @QString fileName=QFileDialog::getSaveFileName(this,tr(“Save File”),QDir::currentPath());@
      First you are getting the filename that is to be saved and then passing it to the QImage using,
      @ QImage image(fileName);@

      But Where is your actual file which is to be cropped ?

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thescouse
        wrote on last edited by
        #3

        Sorry, my mistake, copied the wrong code snippet there...:P
        So can you tell me how to modify the code suitably?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Something like this.
          @
          QImage img("pathtoyourimagefile");
          QImage copy = img.copy(0,0,128,128);@

          Thus "copy" contains the cropped image.

          157

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thescouse
            wrote on last edited by
            #5

            but the image file name was input by the user. How should I code for that?

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Thus when you have done cropping the file ask for user to enter its name.
              So your this code,
              @QString fileName=QFileDialog::getSaveFileName(this,tr(“Save File”),QDir::currentPath());@
              gets the name of the user entered file.
              Then just save the image with that name.
              so,
              @
              QImage img("pathtoyourimagefile");
              QImage copy = img.copy(0,0,128,128);
              copy.save(fileName,"jpg");
              @

              157

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved