C + + image processing-image flip (mirror) __c++

Source: Internet
Author: User
Tags image flip

Reading Tips :

"C + + image processing" series with clear code, readability, all using C + + code.

the Delphi Image Processing "series of focus on efficiency, the general code for Pascal, the core code using BASM."

as much as possible to maintain consistency between the two, can be compared.

This code must include C + + image processing--data types and common functions the BmpData.h header file in the article.

The flip process of the image is to produce a mirror image that is relative to the original image in either horizontal or vertical direction.

The principle of image flip is very simple, in the middle of the image pixel (horizontal direction), or the middle row pixel (vertical) is the base column (row), the pixel of the first column (row) of the image is exchanged with the pixel of the last column (row) of the image, and the pixel of the second column (row) of the image is exchanged with the pixel of the second column (row) ... until the base column (line), if the number of columns (rows) of an image is even, the column (row) that corresponds to the tail, including the Gilead (Row), includes 22 exchanges, and if the number of columns (rows) of the image is even, the Gilead (row) is unchanged, and the other column (row) 22 is exchanged.

Here is the implementation code and example program for image rollover (using BCB2010 and GDI +):

---------------------------------------------------------------------------typedef enum {

Reversalmodehorizontal,//Horizontal flip reversalmodevertical//Vertical flip}reversalmode;
	Image Flip (mirrored) VOID imagereversal (BitmapData *data, Reversalmode mode) {UINT width = data->width;
	UINT height = data->height;
	INT Srcoffset = data->stride >> 2;
	INT Dstoffset, Delta;
	Pargbquad PD, PS;

	ARGB color;
		if (mode = = reversalmodehorizontal) {PD = (Pargbquad) data->scan0;
		PS = pd + width-1;
		Dstoffset = Srcoffset;
		Delta =-1;
	Width >>= 1;
		else {PS = (pargbquad) data->scan0;
		PD = PS + (height-1) * SRCOFFSET;
		Dstoffset =-srcoffset;
		Delta = 1;
	Height >>= 1;
		for (UINT y = 0; y < height; y + +, pd + = dstoffset, PS = = srcoffset) {Pargbquad pd0 = PD;
		Pargbquad PS0 = PS;
			for (UINT x = 0; x < width; x + +, pd0 + +, Ps0 + = Delta) {color = pd0->color;
			*pd0 = *PS0;
        Ps0->color = Color; }
	}
}
//---------------------------------------------------------------------------void __fastcall Tform1::button3click (TObject *sender) { Gdiplus::bitmap *bmp = new Gdiplus::bitmap (L). \\..
	\\media\\IMG_9440_mf.jpg ");
	Gdiplus::graphics *g = new Gdiplus::graphics (canvas->handle);

	Painting original G->drawimage (BMP, 0, 0);
	BitmapData data;
	Lockbitmap (BMP, &data);
	Imagereversal (&data, reversalmodehorizontal);

	Unlockbitmap (BMP, &data); Image G->drawimage (BMP, data) after the flip of the picture.
	Width, 0);
	Delete g;
Delete bmp;
 }
//---------------------------------------------------------------------------

Example after the operation of the mirror image is as follows, the left is the original image, the right side is a horizontal mirror image:

due to the limited level, errors are unavoidable, welcome corrections and guidance. Email address:maozefa@hotmail.com

Here you can access the C + + image processing--the article index.

Related Article

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.