User Guide > Getting Started > Tutorial: Create Your First Project |
In this tutorial, you will create a C/C++ Windows console application and use ImageGear to load an image, resize it, and convert it to a new raster format.
The following tutorial refers specifically to 64-bit installations. For 32-bit installations, throughout these instructions, substitute x64 with x86. |
Using Visual Studio (2010 or later):
C |
Copy Code
|
---|---|
// IG_Tutorial_Console.c : Defines the entry point for the console application. // // Copyright Accusoft Corporation, Tampa Florida. All Rights Reserved. #include "stdafx.h" #include <string.h> #include "gear.h" int _tmain(int argc, _TCHAR* argv[]) { AT_ERRCOUNT errCount = 0; HIGEAR image = 0; AT_LMODE saveFormat = IG_SAVE_UNKNOWN; AT_CHAR inputPath[260]; AT_CHAR formatCode[15]; LPSTR outputPath = "out"; memset(inputPath, 0, sizeof(inputPath)*(sizeof(inputPath[0]))); memset(formatCode, 0, sizeof(formatCode)*(sizeof(formatCode[0]))); fprintf(stdout, "Enter the complete path to the image to be converted: "); fscanf_s(stdin, "%259[^\n]%*c", inputPath); fprintf(stdout, "Enter the format for the new image. Choose from \"BMP\"," "\"GIF\", \"JPG\", \"PNG\" or \"TIFF\": "); fscanf_s(stdin, "%14[^\n]%*c", formatCode); // Match the format code entered to an ImageGear save format handled with this sample. saveFormat = IG_SAVE_UNKNOWN; if (0 == _stricmp(formatCode, "BMP")) { saveFormat = IG_SAVE_BMP_UNCOMP; outputPath = "out.bmp"; } else if (0 == _stricmp(formatCode, "GIF")) { saveFormat = IG_SAVE_GIF; outputPath = "out.gif"; } else if (0 == _stricmp(formatCode, "JPG")) { saveFormat = IG_SAVE_JPG; outputPath = "out.jpg"; } else if (0 == _stricmp(formatCode, "PNG")) { saveFormat = IG_SAVE_PNG; outputPath = "out.png"; } else if (0 == _stricmp(formatCode, "TIFF")) { saveFormat = IG_SAVE_TIF_DEFLATE; outputPath = "out.tif"; } else { fprintf(stdout, "Format is not support in this application."); return 1; } // Open the image. IG_load_file(inputPath, &image); // Resize the image to the width and height specified. // Parameter nInterpMethod indicates the type of interpolation employed. // It may be changed for other values, such as IG_INTERPOLATION_BICUBIC // or IG_INTERPOLATION_NEAREST_NEIGHBOR. IG_IP_resize_ex(image, 150, 150, IG_INTERPOLATION_BILINEAR, 0, 0); // Save the imageto the format selected. errCount = IG_save_file(image, outputPath, saveFormat); // Release the imageobject. IG_image_delete(image); if (errCount == 0) { fprintf(stdout, "Saved %s", outputPath); return 0; } else { fprintf(stdout, "Failed to save %s", outputPath); return 1; } } |
C++ |
Copy Code
|
---|---|
// IG_Tutorial_Console.cpp : Defines the entry point for the console application. // // Copyright Accusoft Corporation, Tampa Florida. All Rights Reserved. #include "stdafx.h" #include <iostream> #include <string> using namespace std; #include "gear.h" int main() { cout << "Enter the complete path to the image to be converted: "; string inputPath; getline(cin, inputPath); cout << "Enter the format for the new image. " "Choose from \"BMP\", \"GIF\", \"JPG\", \"PNG\" or \"TIFF\": "; string formatCode; getline(cin, formatCode); string outputPath("out"); // Match the format code entered to an ImageGear save format handled with this sample. enumIGSaveFormats saveFormat = IG_SAVE_UNKNOWN; if (0 == formatCode.compare("BMP")) { saveFormat = IG_SAVE_BMP_UNCOMP; outputPath = "out.bmp"; } else if (0 == formatCode.compare("GIF")) { saveFormat = IG_SAVE_GIF; outputPath = "out.gif"; } else if (0 == formatCode.compare("JPG")) { saveFormat = IG_SAVE_JPG; outputPath = "out.jpg"; } else if (0 == formatCode.compare("PNG")) { saveFormat = IG_SAVE_PNG; outputPath = "out.png"; } else if (0 == formatCode.compare("TIFF")) { saveFormat = IG_SAVE_TIF_DEFLATE; outputPath = "out.tif"; } else { cout << "Format is not supported in this application."; return EXIT_FAILURE; } // Open the image. HIGEAR image = 0; IG_load_file((LPSTR)inputPath.c_str(), &image); // Resize the image to the width and height specified. // Parameter nInterpMethod indicates the type of interpolation employed. // It may be changed for other values, such as IG_INTERPOLATION_BICUBIC // or IG_INTERPOLATION_NEAREST_NEIGHBOR. IG_IP_resize_ex(image, 150, 150, IG_INTERPOLATION_BILINEAR, 0, 0); // Save the image to the format selected. AT_ERRCOUNT errCount = IG_save_file(image, (LPSTR)outputPath.c_str(), saveFormat); // Release the image object. IG_image_delete(image); if (errCount == 0) { cout << "Saved " << outputPath; return EXIT_SUCCESS; } else { cout << "Failed to save " << outputPath; return EXIT_FAILURE; } } |
C |
Copy Code
|
---|---|
// // To unlock ImageGear for deployment you must call the // IG_lic_solution_name_set() and IG_lic_solution_key_set() and possibly // IG_lic_OEM_license_key_set() functions. // See Licensing section in ImageGear User Manual for more details. // |
C++ |
Copy Code
|
---|---|
// // To unlock ImageGear for deployment you must call the // IG_lic_solution_name_set() and IG_lic_solution_key_set() and possibly // IG_lic_OEM_license_key_set() functions. // See Licensing section in ImageGear User Manual for more details. // |
C |
Copy Code
|
---|---|
// Resize the image to the width and height specified.
// Parameter nInterpMethod indicates the type of interpolation employed.
// It may be changed for other values, such as IG_INTERPOLATION_BICUBIC
// or IG_INTERPOLATION_NEAREST_NEIGHBOR.
IG_IP_resize_ex(image, 150, 150, IG_INTERPOLATION_BILINEAR, 0, 0);
|
C++ |
Copy Code
|
---|---|
// Resize the image to the width and height specified.
// Parameter nInterpMethod indicates the type of interpolation employed.
// It may be changed for other values, such as IG_INTERPOLATION_BICUBIC
// or IG_INTERPOLATION_NEAREST_NEIGHBOR.
IG_IP_resize_ex(image, 150, 150, IG_INTERPOLATION_BILINEAR, 0, 0);
|
The majority of ImageGear functions return either an error code, enumIGErrorCodes, or an error count, AT_ERRCOUNT. For brevity, we ignore ImageGear return values in this sample except for saving. This will allow us to indicate that saving was successful with an appropriate message and exit code. |