Thread: Cropping Images

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    2

    Cropping Images

    Hi!

    So I need a bit of advice right here. Somehow, I need to make a crop function, that will load, crop and save an image. All I've seen in Google or MSDN was C#, VB or scripts related to other programming languages. I've tried the ImageMagick API and some other libs I found on the net, but they didn't seem to work out, since they're quite old. Yeah, I'm probably looking for some source code, or useful GDI functions or a tutorial or whatever. Something that will allow me to make the image cropper.
    Source should be (obivously) C++, with or without GDI and compileable with Microsoft Visual Studio 2005 Pro. Hope someone can help me out!

    Thanks in Advance!, ~mx781

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    What makes you think you'll have more success with a new API compared to an old API?

    > but they didn't seem to work out,
    I mean, what kind of a report is this?
    "I tried mumble and some mumble happened but mumble mumble work"

    If you post your actual code and describe some meaningful symptoms, then we might be able to get you running. Maybe you're just one typo away from success, but there's no way to tell from here with the information you've posted so far.

    Without a basis on which to estimate your skill level, it's impossible to direct you in any meaningful way.

    Some basic questions would be
    - is the library you chose compatible with your compiler?
    - does the library support the file format(s) you have?

    Also, are you looking to do this yourself, or would a ready made solution of some sort also work for you? If so, I might suggest http://www.gimp.org/ and writing a script which performs the operations you want.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    2
    Eh, yeah, sorry for the first noobish post.

    Old API vs new one - yeah, I suppose there is no real reason to think so, but what made me think that way was that older APIs are directed to older compilers, which would perhaps result in incompatibility with newer ones. But yeah, now that I think of it, probably a silly thing to do.

    The API I used is ImageMagick, more specifically the C++ version of it - Magick++. Their site linked to various ftp servers, so I clicked one on random and obtained the supposedly newest version of it from there. The newest one on that server, anyway. I got 6.3.5. The Magick++ folder consists of 4 subfolders - bin, demo, lib and tests. So to check does this thing even work, I was going to compile one of the demo's.. or tests, I see no big difference between them. So I took a .cpp file from the demo folder, copied it's content to my image cropper project, so I don't have to include it or make a new project or wel.. yeah. So once done that, I knew I had to include the libs. So I added the lib folder to the include folders in VS. Why include folders? Because I didn't see any .lib files in there just .cpp and .h and I also saw no pragmas in the file that attempt to use a library anywhere. The bin folder just had to config files in it, so I didn't include that. I didn't read through the source, but tried to compile it now, since I was just testing whether it works or not. Well it said that it cannot include a file, since it doesn't exist. The file was in a "magick" folder, that I could not locate in Magick++ folder or any of it's sub's. I found it in the main folder or ImageMagick, so I thought there could possibly be more things it requires from that folder. Well, it did not give me any other include errors, except 104 unresolved external symbol errors instead. I find these errors confusing, I am not any big-shot C++ pro or whatever, so I asked my friend, which supposedly knows C++ better than me. He told me it means that there are no libraries linked to. Well, so I looked through the Magick++ folder and it's sub's and found no .lib files at all. Possibly they were somewhere in the root of ImageMagick folder, but before I started to check, by friend told me that I should probably check the ReadMe. Yeah, I had "Compilation instructions" open already, and they say this:

    In order to compile Magick++ you must have access to a standard C++ implementation. The author uses gcc 3.1 (GNU C++) which is available under UNIX and under the Cygwin UNIX-emulation environment for Windows. Standards compliant commercial C++ compilers should also work fine. Most modern C++ compilers for Microsoft Windows or the Mac should work (project files are provided for Microsoft Visual C++ 6.0).
    I did not really understand what do those instructions are telling me to do, my friend noted that it's an old lib.. and why can't I just use the built-in GDI functions. We started googling around, but to no avail. No, we did not google for hours, to say that we googled the whole web, but he suggested me to post on the forum, so I did.

    I do not have any source on me, since all I wanted to do is get a base ready, and for that I needed some image-cropping function. Thus I got that API and afterwards googled for GDI functions for this. Found some, but not for C++. And they were for sell anyway. Nothing much, but don't think it's worth it, not knowing if it would help me. So overall, currently I have no source at all, so I don't have anything to post.

    Oh and might I note, that I also downloaded a lib, called CImg, which had a crop function without any advanced stuff. I downloaded it, included all it needed and compiled a demo from it, which in my case was image2ascii, obivously a prog to convert an image to ASCII characters. I ran it, supplying it the required parameter - the directory to my image file. I tried PNG, I tried JPEG, but it error'd me again saying that it cannot load file and that I should make sure I have the ImageMagick package installed. I did not see any installer or whatever was required to install a "package" of ImageMagick, but I suppose that could do with the instructions I posted above.

    And about the basic questions...
    I am not sure if it is, that's why I said it's an old API and could supposedly not support my compiler.
    About number two - no idea, since I couldn't get it to test, it didn't even compile.

    My skill level.. Well, I'd call myself rather low in C++.. like... I know all the basic stuff, how to work with some win32 elements, some specific stuff, but none of the high, pro, advanced stuff.

    About GIMP.. I did not really look into it yet, but I'm not really developping this thing for myself and.. I also need the thumbnail generation to be able to put into a loop. I'm not saying you can't do that with the Scripter, or whatever, I haven't even seen it yet, but I'd mostly prefer to do it myself, to both make it more user-friendly and have a nice interface and to also increase my programming skills. :P

    So... I hope I provided enough information this time!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CBitmap + big images = bad?
    By dug in forum Windows Programming
    Replies: 18
    Last Post: 06-28-2003, 11:53 PM
  2. Images
    By gvector1 in forum C++ Programming
    Replies: 7
    Last Post: 02-25-2003, 09:59 AM
  3. images, icons, and cursors, OH MY!
    By DarkViper in forum Windows Programming
    Replies: 3
    Last Post: 01-07-2003, 02:26 PM
  4. STL, Queues And Images
    By simly01 in forum C++ Programming
    Replies: 3
    Last Post: 06-24-2002, 12:31 PM
  5. A simple question on Images....
    By LonelyPlanetWa in forum C Programming
    Replies: 7
    Last Post: 05-20-2002, 07:34 AM