C# 5

[C#] Captcha

C#으로 Captcha(https://ko.wikipedia.org/wiki/CAPTCHA) 를 구현하는 코드입니다.Google 의 reCaptchar(https://developers.google.com/recaptcha/) 같은 api를 통해서도 spam 이나 bot을 막아주는 비슷한 같은 목적의 개발이 가능합니다. Code Project(http://www.codeproject.com/) 에서 참고하였던 Code를 함수로 제가 쓰기 쉽게 조금 수정한 Code입니다.(결과는 참고페이지 참고) using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing.Text; public ..

The Piece of Code 2016.02.10

[C#] Image Resize - ASP.NET

Web 프로젝트에서 Image Resize 할 때 사용되는 코드입니다. 코드라기보다는 Class 라고 해야겠네요..;;이미지 관련 기능들을 Winform 에서 구현하려면 좀 귀찮은 면이 있었는데 asp.net 에서는 좀 편하게 구현 가능하네요. System.Web.Helpers.WebImage img = new System.Web.Helpers.WebImage(filePath); //img.Resize(width, height, preserveAspectRatio, preventEnlarge); // => Resize //img.FlipHorizontal(); // => 좌우 대칭 //img.FlipVertical(); // => 상하 대칭 //img.Crop(top, left, bottom, right..

The Piece of Code 2016.02.10

[C#] Image Resize - Winfrom

Winform 에서 Image Resize 할 때 사용되는 코드입니다.Stack Overflow에서 보았던 소스를 적어 둡니다. public static System.Drawing.Image Resize(Image image, int Width, int Height, bool needToFill) { int sourceWidth = image.Width; int sourceHeight = image.Height; int sourceX = 0; int sourceY = 0; double destX = 0; double destY = 0; double nScale = 0; double nScaleW = 0; double nScaleH = 0; nScaleW = ((double)Width / (double)s..

The Piece of Code 2016.02.10

[C#] StripHtml

종종 쓰게되는 Html 에서 Text 만 추출하는 함수 입니다. 예전에 외국 블로그에서 받아둔 소스 같은데 출처는 적어두질 못했네요. ㅎ(오랫동안 잊고 지내다가 회사 팀장님이 이런 소스 본적 있냐고 물어보셔서 급! 생각이 나 올려둡니다.)설명하자면 변수(Html)를 Parameter로 받아서 정규식으로 태그를 삭제한 후 Text 만을 Return 하는 소스입니다. //HTML 에서 Text만 추출한다. public static string StripHtml(string Html) { string output; //get rid of HTML tags output = System.Text.RegularExpressions.Regex.Replace(Html, "]*>", string.Empty); //get..

The Piece of Code 2013.01.20

[C#] Base64 Encoding, Decoding

Base64 로 Encoding, Decoding 해주는 함수입니다. Convert 에서 해주긴 하지만 Byte[] 로 변환해 줘야 하는 번거로움이 있어 공통함수로 빼서 쓰는게 편하실 겁니다.(친절한 주석은 Pass~ ^^) namespace Common { class EncodingHelper { public static string Base64Encoding(string EncodingText, System.Text.Encoding oEncoding = null) { if (oEncoding == null) oEncoding = System.Text.Encoding.UTF8; byte[] arr = oEncoding.GetBytes(EncodingText); return System.Convert.T..

The Piece of Code 2012.12.07