This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
6,337 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BTDToolbox.Classes | ||
{ | ||
class ImageProcessing | ||
{ | ||
public string dir = Environment.CurrentDirectory + "\\"; | ||
string[] files = new string[4] { Environment.CurrentDirectory + "\\" + "248.png", Environment.CurrentDirectory + "\\" + "249.png", Environment.CurrentDirectory + "\\" + "250.png", Environment.CurrentDirectory + "\\" + "878.png" }; | ||
|
||
public static System.Drawing.Bitmap CombineBitmap(Bitmap[] files) | ||
{ | ||
//read all images into memory | ||
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>(); | ||
System.Drawing.Bitmap finalImage = null; | ||
|
||
try | ||
{ | ||
int width = 0; | ||
int height = 0; | ||
|
||
foreach (Bitmap image in files) | ||
{ | ||
//create a Bitmap from the file and add it to the list | ||
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image); | ||
|
||
//update the size of the final bitmap | ||
width += bitmap.Width; | ||
height = bitmap.Height > height ? bitmap.Height : height; | ||
image.MakeTransparent(); | ||
images.Add(image); | ||
} | ||
|
||
//create a bitmap to hold the combined image | ||
finalImage = new System.Drawing.Bitmap(width, height); | ||
finalImage.MakeTransparent(); | ||
//get a graphics object from the image so we can draw on it | ||
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage)) | ||
{ | ||
//set background color | ||
//g.Clear(System.Drawing.Color.Black); | ||
g.Clear(System.Drawing.Color.Transparent); | ||
|
||
//go through each image and draw it on the final image | ||
int offset = 0; | ||
foreach (System.Drawing.Bitmap image in images) | ||
{ | ||
g.DrawImage(image, | ||
new System.Drawing.Rectangle(offset, 0, image.Width, image.Height)); | ||
//offset += image.Width; | ||
} | ||
} | ||
|
||
return finalImage; | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (finalImage != null) | ||
finalImage.Dispose(); | ||
|
||
//return finalImage; | ||
throw ex; | ||
} | ||
finally | ||
{ | ||
//clean up memory | ||
foreach (System.Drawing.Bitmap image in images) | ||
{ | ||
image.Dispose(); | ||
} | ||
} | ||
} | ||
|
||
|
||
public static System.Drawing.Bitmap CombineBitmap2(string[] files) | ||
{ | ||
//read all images into memory | ||
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>(); | ||
System.Drawing.Bitmap finalImage = null; | ||
|
||
try | ||
{ | ||
int width = 0; | ||
int height = 0; | ||
|
||
foreach (string image in files) | ||
{ | ||
//create a Bitmap from the file and add it to the list | ||
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image); | ||
|
||
//update the size of the final bitmap | ||
width += bitmap.Width; | ||
height = bitmap.Height > height ? bitmap.Height : height; | ||
|
||
images.Add(bitmap); | ||
} | ||
|
||
//create a bitmap to hold the combined image | ||
finalImage = new System.Drawing.Bitmap(width, height); | ||
|
||
//get a graphics object from the image so we can draw on it | ||
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage)) | ||
{ | ||
//set background color | ||
g.Clear(System.Drawing.Color.Black); | ||
|
||
//go through each image and draw it on the final image | ||
int offset = 0; | ||
foreach (System.Drawing.Bitmap image in images) | ||
{ | ||
g.DrawImage(image, | ||
new System.Drawing.Rectangle(offset, 0, image.Width, image.Height)); | ||
//offset += image.Width; | ||
} | ||
} | ||
|
||
return finalImage; | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (finalImage != null) | ||
finalImage.Dispose(); | ||
|
||
throw ex; | ||
} | ||
finally | ||
{ | ||
//clean up memory | ||
foreach (System.Drawing.Bitmap image in images) | ||
{ | ||
image.Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.