public static ReturnValues <Image> CreateThumbnail(string filePath, int width, int height) { var result = new ReturnValues <Image>(); try { FileInfo fi = new FileInfo(filePath); if (fi.Exists) { using (FileStream fs = File.OpenRead(fi.FullName)) using (Image image = Image.FromStream(fs, false, false)) using (Image pThumbnail = image.GetThumbnailImage(width, height, delegate { return(false); }, IntPtr.Zero)) { result.Success(fi.Length, pThumbnail); } } else { result.Error("대상 파일이 존재하지 않습니다."); } } catch (Exception ex) { result.Error(ex); } return(result); }
public ReturnValues <Papago> Translation(Papago data, IWebClient wc) { var result = new ReturnValues <Papago>(); if (string.IsNullOrWhiteSpace(data.text)) { result.Error("번역 대상이 없습니다."); } else if (data.text.Trim().Length >= 5000) { result.Error("1회 번역 최대 문자열은 5000 글자 입니다."); } else { try { string tmp = wc.DownloadString(data.CreateURL()); if (!string.IsNullOrWhiteSpace(tmp)) { HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(tmp); HtmlAgilityPack.HtmlNode targetObject = document.GetElementbyId("txtTarget"); if (targetObject != null) { data.Result = targetObject.InnerText.Trim(); result.Success(1, data); } else { var nodes = document.DocumentNode.SelectSingleNode("//div[@id='txtTarget']"); if (nodes != null) { data.Result = nodes.InnerText.Trim(); result.Success(1, data); } else { result.Error("Not Found Target!!!!"); result.Value = tmp; } } } } catch (Exception ex) { result.Error(ex); if (this.Logger != null) { this.Logger.Error(ex); } } } return(result); }
public static ReturnValues <Image> CreateCrop(string filePath, int width, int height) { var result = new ReturnValues <Image>(); try { FileInfo fi = new FileInfo(filePath); if (fi.Exists) { using (FileStream fs = File.OpenRead(fi.FullName)) using (Image image = Image.FromStream(fs, false, false)) { if (image.Width > width && image.Height > height) { Point point = new Point(); point.X = (image.Width - width) / 2; if (height > (image.Height * 2)) { point.Y = height / 2; } else { point.Y = (image.Height - height) / 2; } Rectangle cropRect = new Rectangle(point, new Size(width, height)); Bitmap src = image as Bitmap; result.Data = src.Clone(cropRect, image.PixelFormat); result.Check = true; result.Value = "Crop"; result.Code = fi.Length; } else { result.Data = image.GetThumbnailImage(width, height, delegate { return(false); }, IntPtr.Zero); result.Check = true; result.Value = "Thumbnail"; result.Code = fi.Length; } } } else { result.Error("대상 파일이 존재하지 않습니다."); } } catch (Exception ex) { result.Error(ex); } return(result); }
public static ReturnValues <List <long> > FindLastKey(ContentResolver resolver) { var result = new ReturnValues <List <long> >(); try { System.String[] reqCols = new System.String[] { "_id" }; Android.Net.Uri sentURI = Android.Net.Uri.Parse($"content://mms/inbox"); var cursor = resolver.Query(sentURI, reqCols, null, null, "date DESC"); if (cursor != null) { long point = 0; List <long> cursors = new List <long>(); for (int i = 0; i < cursor.Count && cursor != null; i++) { if (cursor.MoveToFirst()) { cursor.Move(i); string tmp = cursor.GetString(cursor.GetColumnIndex("_id")); if (!string.IsNullOrWhiteSpace(tmp)) { if (long.TryParse(tmp, out point)) { cursors.Add(point); } } } } if (cursors != null && cursors.Count > 0) { result.Success(cursors.Max(), cursors); } else { result.Error("Not Found"); } } } catch (Exception ex) { result.Error(ex); } return(result); }