Free image Simple to use

Source: Internet
Author: User

Freeimage Introduction

Freeimage is a Open Source library project for developers who would like to support popular graphics image formats like P NG, BMP, JPEG, TIFF and others as needed by today's multimedia applications. Freeimage is easy-to-use, fast, multithreading safe, compatible with all 32-bit or 64-bit versions of Windows, and Cross-p Latform (works both with Linux and Mac OS X).

In short, it is a cross-platform lightweight image library. This is the library that appears to be loaded with cocos2d images.


SOURCE Download-Freeimage 3.16


Compile

Environment-Windows 8.1

VS2008 (in order to compile this specially installed)

Download the source code, after extracting the root directory has compiled project files, directly open the compilation is good. Debug and release are compiled again.

After compiling, there are FreeImage.dll, FreeImage.lib, FreeImaged.dll, freeimaged.lb.


Next compile the C + + Wraper.

Open this project, X:\FreeImageSource\Wrapper\FreeImagePlus\FreeImagePlus.2008.sln.

As with just now, debug and release are compiled again.


Next compile the test project for C + + Wraper

X:\FreeImageSource\Wrapper\FreeImagePlus\test\fipTest.2008.sln

Copy the outermost test.jpg to the running directory and perform four Tests in one step.



Problems that you may encounter


No header file found

The directory where the header files are added here


Lib not found

Add in the following location



It's not a DLL.

Copy the corresponding DLL to the program run directory


Test program crashes

Copy the test.jpg to the running directory.


Simple to use

Create a project and use a picture.


(Call me Leifeng.)


The simplest thing to do is to load a JPEG image .

#include "stdafx.h" #include <iostream> #include "FreeImagePlus.h" int _tmain (int argc, _tchar* argv[]) {Freeimage_ Initialise (TRUE); Fibitmap * JPEG = Freeimage_load (Fif_jpeg, "test.jpg", jpeg_default);//Gets the width of the image, in pixels, int width = freeimage_getwidth ( JPEG); int Height = freeimage_getheight (jpeg); std::cout << width: << width <<  "\nheight:"  & Lt;


Color Adjustment

Common picture Color Adjustment freeimage have been implemented, call the corresponding interface can be. This calls a reversed color, and there is an adjustment curve.



(Let me wipe the nosebleed first)

Code

Freeimage_adjustcontrast (JPEG, 15.0); Freeimage_adjustbrightness (JPEG, 50.0),//freeimage_invert (JPEG), if (JPEG) {freeimage_save (fif_bmp, JPEG, "test.bmp") , Bmp_default);}


copy of GIF

Create an identical GIF from a GIF

  BOOL Bmemorycache = true;fipmultipage src (bmemorycache); fipmultipage DST (Bmemorycache);// You must declare this before using it. We'll use the assignement operator, i.e operator= () fipimage image;//Open src file (read-only, use memory cache) src. Open ("Example.gif", FALSE, TRUE), if (Src.isvalid ()) {//Open DST file (creation, use memory cache) Dst.open ("Output.gif", T RUE, FALSE);//Get src page countint count = Src.getpagecount ();//Clone src to dstfor (int page = 0; page < count; pag e++) {//Load the bitmap at position ' page ' image = Src.lockpage (page), if (Image.isvalid ()) {//Add a new bitmap to DSTDST. Appendpage (image);//Unload the bitmap (do not apply any change to SRC) src.unlockpage (image, FALSE);}} Std::cout << Freeimage_getpagecount (DST) << std::endl;//Close srcsrc.close (0);//Save and Close Dstdst.close (); 


View GIF's Metadate

Fipmultipage src (bmemorycache); Src.open ("Example.gif", FALSE, TRUE); Fipimage image;image = src.lockpage (0); Fipmetadatafind finder;if (Finder.findfirstmetadata (fimd_animation, image, Tagg)) {do {//process the Tagconst void * p = Tagg.getvalue ();D word* pp = (DWORD *) p;cout << "Process the tag:" << Tagg.getkey () << "<<tagg. GetType () << "" << *pp << endl;tagvector.push_back (Tagg);} while (Finder.findnextmetadata (Tagg));}

Finally run out remember Unlockpage.

Random loading a GIF, get the tag with the following

The most important of these is frametime, which represents the time the frame occupies, in milliseconds. Next is loop, which is a loop (0) or loop once (1),


Generate GIF from a static picture

Download a few PNG first


The question stuck me for almost a day, and the document was full of pits.

First, the code in the document specifically says GIF generated

Assume we have an array of dibs which is already 8bpp and all the same size,//And some float called FPS for frames P Er secondfimultibitmap *multi = freeimage_openmultibitmap (fif_gif, "Output.gif", TRUE, FALSE);D word dwframetime = (DWORD ) ((1000.0f/fps) + 0.5f); for (int i = 0; i <; i++) {/-Clear any animation metadata used by this DIB as we ' ll addin G Our own onesfreeimage_setmetadata (Fimd_animation, dib[i], NULL, NULL);//Add ANIMATION tags to dib[i]fitag *tag = Freeim Age_createtag (); if (tag) {Freeimage_settagkey (tag, "frametime"); Freeimage_settagtype (tag, fidt_long); Freeimage_settagcount (tag, 1); Freeimage_settaglength (tag, 4); Freeimage_settagvalue (tag, &dwframetime); Freeimage_setmetadata (Fimd_animation, Dib[i], Freeimage_gettagkey (tag), tag); Freeimage_deletetag (tag);} Freeimage_appendpage (Multi, Dib[i]);} Freeimage_closemultibitmap (multi);

It seems that a multibitmap is created first, and then various appendpage are available.

Too Young.


Look at the GIF file format first

GIF format is a specially developed picture format for making pictures available on online applications. Gif, sometimes also known as "Giff", is a lossless, 8-bit picture format. "Lossless" means 100% of the pixel data information that keeps the original image. The professional noun "8-bit" means the color depth that can be represented--a 8-bit image can only support a maximum of 256 different colors (a picture of an extra 256 colors will appear distorted if it is saved with a GIF image).


So, the above PNG is 32bit, not the 8-bit picture is not append, then the format Bai.

Comes with a convertto8bits method, but the conversion is grayscale.

On the forum to search for answers, let's just say that.

To use a Colorquantize method, the result is completely invalid, on the search, tell the 24-bit image to turn.

Keep turning, the transparent parts are all black.


Search on forum without fruit, go back to the format of PNG

PNG picture type
The PNG format has 8-bit, 24-bit, 32-bit three, and the following are some of the terms:

Index transparency: Similar to GIF, a pixel has only full and full opacity effects
Alpha Transparent: Translucent
PNG8-8-bit PNG supports up to 256 (2 of 8-square) colors, and 8-bit PNG supports index transparency and alpha transparency.
PNG24-Supports 2 of 24 seed colors, but does not support transparent information.
The png32-32-bit PNG adds 8 bits of transparent information on a 24-bit PNG basis, thus supporting varying degrees of semi-transparent effects.

Silently opens the Fart ace (PS), loads the picture, stores the format used for the Web.



Re-written in code, Appendpage, the world is quiet.

Code listings (plus wraper)

#include "stdafx.h" #include <iostream> #include "FreeImagePlus.h" using namespace std;int _tmain (int argc, _tchar* Argv[]) {BOOL Bmemorycache = true;fipmultipage DST (bmemorycache); Fipimage image1;image1.load ("11.png"); fipimage Image2;image2.load ("2.png"); Fipimage image3;image3.load ("3.png"); Image2.convertto24bits (); Image2.colorquantize ( fiq_wuquant); Image3.convertto24bits (); image3.colorquantize (fiq_wuquant); float fps = 3.0f;dword dwframetime = (DWORD) ((1000.0f/fps) + 0.5f); Fiptag tag;tag.setkey ("Frametime"); Tag.settype (Fidt_long); Tag.setcount (1); tag.setlength (4); Tag.setvalue (&dwframetime); const void * p = Tag.getvalue ();D word* pp = (DWORD *) p;cout << "Tag" << Tag.getkey () << "" << *pp << endl;// Set the loop of gif 0->loop forever 1->loop only once. DWORD Bloop = (DWORD) (1); Fiptag Looptag;looptag.setkey ("Loop"); Looptag.settype (Fidt_long); Looptag.setcount (1); Looptag.setlength (4); Looptag.setvalue (&bloop); Image1.setmetadata (Fimd_animation, tAg.getkey (), tag), Image2.setmetadata (Fimd_animation, Tag.getkey (), tag), Image3.setmetadata (Fimd_animation, Tag.getkey (), tag); Image1.setmetadata (Fimd_animation, Looptag.getkey (), Looptag); Image2.setmetadata (FIMD_ ANIMATION, Looptag.getkey (), Looptag), Image3.setmetadata (Fimd_animation, Looptag.getkey (), Looptag);d St.open (" Output.gif ", TRUE, FALSE);d st.appendpage (image1);d st.appendpage (image2);d st.appendpage (image3);d st.close (); return 0;}

Final effect, guang~


The first PNG is a 8-bit PNG exported by PS, followed by two 8 bits of code.



Free image Simple to use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.