protected void btnCreate_Click(object sender, EventArgs e) { Thread thread = new Thread(() => WebPageBitmap.InitBitmap("wtest3", ShareMode.Question, "")); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); }
public static void LoadBitmapSTA(String word, String path) { Thread thread = new Thread(() => WebPageBitmap.InitBitmap(word, ShareMode.Question, path)); // make sure bitmap exists thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); }
// lazy get - create only if not existing public static void InitBitmap(String word, ShareMode mode, String path) { if (!File.Exists(Path.Combine(Config.SaveFolder, GetFilename(word, mode)))) { WebPageBitmap wpb = new WebPageBitmap(word, mode, path); wpb.SaveBitmap(); } return; }
public String SaveBitmap(int thumbwidth = 400, int thumbheight = 209) { try { String loc = GetFilename(word); Bitmap image = null; WebPageBitmap wpb = new WebPageBitmap(word, mode, webroot); if (!wpb.Fetch()) { throw new ApplicationException("Cannot generate image"); } image = wpb.GetBitmap(thumbwidth, thumbheight); image.Save(System.IO.Path.Combine(Config.SaveFolder, loc)); return(loc); } catch (Exception e) { throw new ApplicationException("Saving bitmap failed", e); } }
public static String GetImagePath(String word, ShareMode mode) { return(Config.WebRoot + "img/" + WebPageBitmap.GetFilename(word, ShareMode.Question)); }