C # merge Images

Source: Internet
Author: User

As follows:Code, Put it in this place, and then you can view how to write such code .....

1: write on the image and set the background color

# Region tree node creation icon
/// <Summary>
/// Create a tree node icon
/// </Summary>
/// <Param name = "TXT"> </param>
/// <Param name = "txtcolor"> </param>
/// <Returns> </returns>
Private bitmap createnodeimg (string txt, color txtcolor)
{
If (txtcolor = color. Transparent)
Txtcolor = color. Black;
Bitmap newbitmap = new Bitmap (12, 14 );
Graphics G = graphics. fromimage (newbitmap );
If (txtcolor! = Color. Black)
{
G. Clear (txtcolor); // background color
}
G. textrenderinghint = system. Drawing. Text. textrenderinghint. antialias;

Fontfamily fm = new fontfamily ("Arial ");
Font font = new font (FM, 12, fontstyle. Regular, graphicsunit. pixel );
Solidbrush sb = new solidbrush (color. Black );

G. drawstring (txt, Font, Sb, new pointf (0, 0 ));
G. Dispose ();
Return newbitmap;
}

 

2. Merge Images

# Region merge Images
/// <Summary>
/// Merge Images
/// </Summary>
/// <Param name = "maps"> </param>
/// <Returns> </returns>
Private bitmap mergerimg (Params bitmap [] maps)
{
Int I = maps. length;
If (I = 0)
Throw new exception ("the number of images cannot be 0 ");

// Create an image object to be displayed and set the width based on the number of parameters
Bitmap backgroudimg = new Bitmap (I * 12, 16 );
Graphics G = graphics. fromimage (backgroudimg );

// Clear the canvas and set the background to white
G. Clear (system. Drawing. color. White );

For (Int J = 0; j <I; j ++)
{
G. drawimage (maps [J], J * 11, 0, maps [J]. Width, maps [J]. Height );
}
G. Dispose ();
Return backgroudimg;
}
# Endregion

# Region merge Images
/// <Summary>
/// Merge Images
/// </Summary>
/// <Param name = "bitmapdic"> </param>
/// <Returns> </returns>
Private bitmap mergerimg (Dictionary <string, bitmap> bitmapdic)
{
If (bitmapdic = NULL | bitmapdic. Count = 0)
Throw new exception ("the number of images cannot be 0 ");
// Create an image object to be displayed and set the width based on the number of parameters
Bitmap backgroudimg = new Bitmap (bitmapdic. Count * 12, 16 );
Graphics G = graphics. fromimage (backgroudimg );

// Clear the canvas and set the background to white
G. Clear (system. Drawing. color. White );

Int J = 0;
Foreach (keyvaluepair <string, bitmap> entry in bitmapdic)
{
Bitmap map = entry. value;
G. drawimage (MAP, J * 11, 0, map. Width, map. Height );
J ++;
}
G. Dispose ();
Return backgroudimg;
}

 

You can also merge images:

// Int I = maps. length;
// If (I = 0)
// Throw new exception ("the number of images cannot be 0 ");

//// Create the image object to be displayed and set the width based on the number of parameters
// Bitmap backgroudimg = new Bitmap (I * 16, 16 );
// Graphics G = graphics. fromimage (backgroudimg );

/// Clear the canvas and set the background to white
// G. Clear (system. Drawing. color. White );

// G. drawimageunscaled (maps [0], 0, 0 );
// G. drawimageunscaled (maps [1], maps [0]. Width, 0 );

// G. Dispose ();
// Return backgroudimg;

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.