private void MakeCert(JDJLFM jdjlfm, RawTemplate template, string[] A) { var baseDirectory = Directory.GetCurrentDirectory(); var imgQRC = Path.Combine(baseDirectory, @"wwwroot\Temp\" + jdjlfm.ID + ".png"); if (!File.Exists(imgQRC)) { System.DrawingCore.Image image = SJCLQRCode.GetQRCode(jdjlfm.ID.ToString(), 2); // ID 二维码 image.Save(imgQRC); } Document doc = new Document(); doc.LoadFromFileInReadMode(Path.Combine(baseDirectory, @"wwwroot\DocTemp\" + template.QJMCBM + ".docx"), Spire.Doc.FileFormat.Docx); string Y1 = jdjlfm.JDRQ.Year.ToString(); string M1 = jdjlfm.JDRQ.Month.ToString().PadLeft(2, '0'); string D1 = jdjlfm.JDRQ.Day.ToString().PadLeft(2, '0'); string Y2 = ""; string M2 = ""; string D2 = ""; var tmpFieldNames = new string[] { "QRC", "ZSBH", "DWMC", "QJMC", "XHGG", "CCBH", "ZZC", "JDRQY", "JDRQM", "JDRQD", "YXQZY", "YXQZM", "YXQZD", "A01", "A02", "A03", "A04", "A05", "A06", "A07", "A08", "A09", "A10" }; var tmpFieldValues = new string[] { imgQRC, jdjlfm.ZSBH, jdjlfm.DWMC, jdjlfm.QJMC, jdjlfm.XHGG, jdjlfm.CCBH, jdjlfm.ZZC, Y1, M1, D1, Y2, M2, D2, A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9] }; //创建合并图片自定义事件 doc.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MailMerge_MergeImageField); //合并模板 doc.MailMerge.Execute(tmpFieldNames, tmpFieldValues); doc.SaveToFile(Path.Combine(baseDirectory, "wwwroot\\Results\\Doc\\" + DateTime.Now.Year + "\\" + template.QJMCBM + "\\" + jdjlfm.ID + ".docx"), Spire.Doc.FileFormat.Docx); try { File.Delete(imgQRC); } catch { } }
private void LoadEnvMap() { if (mTutorial < 5) { return; } string texturePath = Path.GetFullPath(EnvMapPath); Bitmap image = new Bitmap(Image.FromFile(texturePath)); if (image == null) { return; } var imgData = image.LockBits(new System.DrawingCore.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat); BufferDesc bufferDesc = new BufferDesc() { Width = (uint)image.Width, Height = (uint)image.Height, Format = Format.UByte4, Type = BufferType.Input }; Buffer textureBuffer = new Buffer(OptixContext, bufferDesc); int stride = imgData.Stride; int numChannels = 4; unsafe { byte *src = (byte *)imgData.Scan0.ToPointer(); BufferStream stream = textureBuffer.Map(); for (int h = 0; h < image.Height; h++) { for (int w = 0; w < image.Width; w++) { UByte4 color = new UByte4(src[(image.Height - h - 1) * stride + w * numChannels + 2], src[(image.Height - h - 1) * stride + w * numChannels + 1], src[(image.Height - h - 1) * stride + w * numChannels + 0], 255); stream.Write <UByte4>(color); } } textureBuffer.Unmap(); } image.UnlockBits(imgData); TextureSampler texture = new TextureSampler(OptixContext, TextureSamplerDesc.GetDefault(WrapMode.Repeat)); texture.SetBuffer(textureBuffer); OptixContext["envmap"].Set(texture); }
public void Create_Gif_Img_To_Png_Test() { var isExists = File.Exists(imageGifPath); Assert.IsTrue(isExists, "文件存在"); AnimatedGifDecoder de = new AnimatedGifDecoder(); de.Read(imageGifPath); for (int i = 0, count = de.GetFrameCount(); i < count; i++) { System.DrawingCore.Image frame = de.GetFrame(i); frame.Save(outputFilePath + Guid.NewGuid().ToString() + ".png"); } }
/// <summary> /// /// </summary> /// <param name="imageGifPath"></param> /// <param name="outputFilePath"></param> /// <returns></returns> public ReturnValues DecomposeAminmate(string imageGifPath, string outputFilePath, string fileNamePrefix = null, string FileNameSuffix = ".png") { var isExists = File.Exists(imageGifPath); if (!isExists) { return(new ReturnValues() { Success = false }); } AnimatedGifDecoder de = new AnimatedGifDecoder(); de.Read(imageGifPath); List <string> list = new List <string>(); for (int i = 0, count = de.GetFrameCount(); i < count; i++) { if (string.IsNullOrWhiteSpace(fileNamePrefix)) { fileNamePrefix = Guid.NewGuid().ToString(); } outputFilePath = outputFilePath + fileNamePrefix + FileNameSuffix; try { System.DrawingCore.Image frame = de.GetFrame(i); frame.Save(outputFilePath); } catch (Exception ex) { Console.WriteLine("捕获异常,不处理" + ex.Message); } list.Add(outputFilePath); } return(new ReturnValues() { Success = list.Count == de.GetFrameCount() ? true : false, FrameCount = de.GetFrameCount(), Delay = de.GetDelay(0), FrameSize = de.GetFrameSize(), OutputFilePaths = list, }); }
// FIXME - Should we be returning empty bitmap, or null? public virtual void Initialize(Type type) { CheckUnlocked(); if (type == null) { return; } AssemblyName = type.Assembly.GetName(); DisplayName = type.Name; TypeName = type.FullName; // seems to be a right place to create the bitmap System.DrawingCore.Image image = null; foreach (object attribute in type.GetCustomAttributes(true)) { ToolboxBitmapAttribute tba = attribute as ToolboxBitmapAttribute; if (tba != null) { image = tba.GetImage(type); break; } } //fallback: check for image even if not attribute if (image == null) { image = ToolboxBitmapAttribute.GetImageFromResource(type, null, false); } if (image != null) { Bitmap = (image as Bitmap); if (Bitmap == null) { Bitmap = new Bitmap(image); } } Filter = type.GetCustomAttributes(typeof(ToolboxItemFilterAttribute), true); }
public string UpladFilePIC(long?id) //id传过来,如需保存可以备用 { IFormCollection fc = HttpContext.Request.Form; string savePath = string.Empty; int code = 0; string msg = ""; string base64 = fc["base"]; if (base64 != null) { string[] spl = base64.Split(','); string getImgFormat = spl[0].Split(':')[1].Split('/')[1].Split(';')[0]; byte[] arr2 = Convert.FromBase64String(spl[1]); //上传到服务器 DateTime today = DateTime.Today; string md5 = CommonHelper.CalcMD5(spl[1]); string upFileName = md5 + "." + getImgFormat; //生成随机文件名( System.Guid.NewGuid().ToString() ) var pathStart = ConfigHelper.GetSectionValue("FileMap:ImgPath") + DateTime.Now.Year + "/" + DateTime.Now.Month + "/"; if (System.IO.Directory.Exists(pathStart) == false) //如果不存在新建 { System.IO.Directory.CreateDirectory(pathStart); } var filePath = pathStart + upFileName; string pathNew = ConfigHelper.GetSectionValue("FileMap:ImgWeb") + filePath.Replace(ConfigHelper.GetSectionValue("FileMap:ImgPath"), ""); using (MemoryStream memoryStream = new MemoryStream(arr2, 0, arr2.Length)) { memoryStream.Write(arr2, 0, arr2.Length); System.DrawingCore.Image image = System.DrawingCore.Image.FromStream(memoryStream); // 转成图片 image.Save(filePath); // 将图片存到本地 code = 1; msg = pathNew; } } string jsonResult = CommonHelper.GetJsonResult(code, msg); return(jsonResult); }
internal PageImage GetPageImage(Report rpt, Row row) { string mtype = null; Stream strm = null; System.DrawingCore.Image im = null; PageImage pi = null; WorkClass wc = GetWC(rpt); if (wc.PgImage != null) { // have we already generated this one // reuse most of the work; only position will likely change pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH); pi.Name = wc.PgImage.Name; // this is name it will be shared under return(pi); } try { strm = GetImageStream(rpt, row, out mtype); if (strm == null) { rpt.rl.LogError(4, string.Format("Unable to load image {0}.", this._Value == null?"": this._Value.EvaluateString(rpt, row))); return(null); } im = System.DrawingCore.Image.FromStream(strm); int height = im.Height; int width = im.Width; MemoryStream ostrm = new MemoryStream(); ImageFormat imf; // if (mtype.ToLower() == "image/jpeg") //TODO: how do we get png to work // imf = ImageFormat.Jpeg; // else imf = ImageFormat.Jpeg; System.DrawingCore.Imaging.ImageCodecInfo[] info; info = ImageCodecInfo.GetImageEncoders(); EncoderParameters encoderParameters; encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.DrawingCore.Imaging.Encoder.Quality, ImageQualityManager.EmbeddedImageQuality); System.DrawingCore.Imaging.ImageCodecInfo codec = null; for (int i = 0; i < info.Length; i++) { if (info[i].FormatDescription == "JPEG") { codec = info[i]; break; } } im.Save(ostrm, codec, encoderParameters); byte[] ba = ostrm.ToArray(); ostrm.Close(); pi = new PageImage(imf, ba, width, height); pi.SI = new StyleInfo(); // this will just default everything if (_BackgroundRepeat != null) { string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower(); switch (r) { case "repeat": pi.Repeat = ImageRepeat.Repeat; break; case "repeatx": pi.Repeat = ImageRepeat.RepeatX; break; case "repeaty": pi.Repeat = ImageRepeat.RepeatY; break; case "norepeat": default: pi.Repeat = ImageRepeat.NoRepeat; break; } } else { pi.Repeat = ImageRepeat.Repeat; } if (_ConstantImage) { wc.PgImage = pi; // create unique name; PDF generation uses this to optimize the saving of the image only once pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString(); // create unique name } } finally { if (strm != null) { strm.Close(); } if (im != null) { im.Dispose(); } } return(pi); }
override internal void RunPage(Pages pgs, Row row) { Report rpt = pgs.Report; if (IsHidden(pgs.Report, row)) { return; } _ChartMatrix.RunReset(rpt); Rows _Data = GetFilteredData(rpt, row); SetMyData(rpt, _Data); SetPagePositionBegin(pgs); if (!AnyRowsPage(pgs, _Data)) // if no rows return { return; // nothing left to do } // Build the Chart bitmap, along with data regions Page p = pgs.CurrentPage; ChartBase cb = null; try { cb = RunChartBuild(rpt, row); // Build the chart if (!_isHYNEsWonderfulVector.EvaluateBoolean(rpt, row)) //AJM GJL 14082008 'Classic' Rendering { System.DrawingCore.Image im = cb.Image(rpt); // Grab the image int height = im.Height; // save height and width int width = im.Width; MemoryStream ostrm = new MemoryStream(); /* The following is a new image saving logic which will allow for higher * quality images using JPEG with 100% quality * 06122007AJM */ System.DrawingCore.Imaging.ImageCodecInfo[] info; info = ImageCodecInfo.GetImageEncoders(); EncoderParameters encoderParameters; encoderParameters = new EncoderParameters(1); // 20022008 AJM GJL - Centralised class with global encoder settings encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, ImageQualityManager.ChartImageQuality); System.DrawingCore.Imaging.ImageCodecInfo codec = null; for (int i = 0; i < info.Length; i++) { if (info[i].FormatDescription == "JPEG") { codec = info[i]; break; } } im.Save(ostrm, codec, encoderParameters); // 06122007AJM The follow has been replaced with the code above //im.Save(ostrm, info); // generate a jpeg TODO: get png to work with pdf byte[] ba = ostrm.ToArray(); ostrm.Close(); PageImage pi = new PageImage(IMAGEFORMAT, ba, width, height); // Create an image RunPageRegionBegin(pgs); SetPagePositionAndStyle(rpt, pi, row); pi.SI.BackgroundImage = null; // chart already has the background image if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty()) { // force page break if it doesn't fit on the page pgs.NextOrNew(); pgs.CurrentPage.YOffset = OwnerReport.TopOfPage; if (this.YParents != null) { pi.Y = 0; } } p = pgs.CurrentPage; p.AddObject(pi); // Put image onto the current page RunPageRegionEnd(pgs); if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt)) { float newY = pi.Y + pi.H; p.YOffset += newY; // bump the y location } SetPagePositionEnd(pgs, pi.Y + pi.H); } else //Ultimate Rendering - Vector //AJM GJL 14082008 { System.DrawingCore.Imaging.Metafile im = cb.Image(rpt); // Grab the image //im could still be saved to a bitmap at this point //if we were to offer a choice of raster or vector, it would probably //be easiest to draw the chart to the EMF and then save as bitmap if needed int height = im.Height; // save height and width int width = im.Width; byte[] ba = cb._aStream.ToArray(); cb._aStream.Close(); PageImage pi = new PageImage(ImageFormat.Wmf, ba, width, height); RunPageRegionBegin(pgs); SetPagePositionAndStyle(rpt, pi, row); pi.SI.BackgroundImage = null; // chart already has the background image if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty()) { // force page break if it doesn't fit on the page pgs.NextOrNew(); pgs.CurrentPage.YOffset = OwnerReport.TopOfPage; if (this.YParents != null) { pi.Y = 0; } } p = pgs.CurrentPage; //GJL 25072008 - Charts now draw in EMFplus format and not in bitmap. Still using the "PageImage" for the positioning //paging etc, but we don't add it to the page. // ****************************************************************************************************************** // New EMF Processing... we want to add the EMF Components to the page and not the actual EMF... EMF emf = new EMF(pi.X, pi.Y, width, height); emf.ProcessEMF(ba); //Process takes the bytearray of EMFplus data and breaks it down into lines,ellipses,text,rectangles //etc... There are still a lot of GDI+ functions I haven't got to (and some I have no intention of getting to!). foreach (PageItem emfItem in emf.PageItems) { p.AddObject(emfItem); } // ****************************************************************************************************************** //p.AddObject(pi); RunPageRegionEnd(pgs); pi.Y += p.YOffset; if (!this.PageBreakAtEnd && !IsTableOrMatrixCell(rpt)) { float newY = pi.Y + pi.H; p.YOffset += newY; // bump the y location } SetPagePositionEnd(pgs, pi.Y + pi.H); //our emf size seems to be bigger than the jpeg... } } catch (Exception ex) { rpt.rl.LogError(8, string.Format("Exception in Chart handling.\n{0}\n{1}", ex.Message, ex.StackTrace)); } finally { if (cb != null) { cb.Dispose(); } } return; }