Created
August 12, 2015 10:46
-
-
Save whoo24/c5d34470bb963b2634ed to your computer and use it in GitHub Desktop.
It splits two images from given image file.
This file contains hidden or 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
using System; | |
using System.Drawing; | |
namespace split_jpg { | |
class Program { | |
static void Main (string[] args) { | |
try { | |
string filename = args[0]; | |
Bitmap src = Image.FromFile(filename) as Bitmap; | |
int split = 2; | |
int width = src.Width / split; | |
for (int i = 0; i < split; ++i) { | |
int x = width * i; | |
Rectangle crop = new Rectangle(x, 0, width, src.Height); | |
Bitmap target = new Bitmap(crop.Width, crop.Height); | |
using (Graphics g = Graphics.FromImage(target)) { | |
g.DrawImage(src, new Rectangle(0, 0, crop.Width, crop.Height), crop, GraphicsUnit.Pixel); | |
} | |
target.Save(string.Format("{0}_{1}.jpg", filename, i + 1), System.Drawing.Imaging.ImageFormat.Jpeg); | |
} | |
} catch (Exception ex) { | |
Console.WriteLine(ex.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment