C#打印base64 GIF图像

时间:2018-10-09 22:05:09

标签: c# api base64 shipping ups

我有一个从UPS API调用返回的base64字符串,其中包含GIF格式的运输标签。我尝试使用下面的代码打印标签,但是标签质量下降并且像素化。有没有更好的方法来打印此图而又不损失质量。谢谢!

// this is my base64 string
byte[] data = System.Convert.FromBase64String(dobj["ShipmentResponse"]  
["ShipmentResults"]["PackageResults"]["ShippingLabel"] 
["GraphicImage"].ToString());

Image image;
using (MemoryStream ms = new MemoryStream(data))
{
   image = Image.FromStream(ms);
}

PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.Landscape = true;                                                                          

Bitmap bit = new Bitmap(image);                                          
bit.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

pd.PrintPage += (sender, args) =>
{

   args.Graphics.InterpolationMode = 
   System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
   args.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
   args.Graphics.DrawImage(bit, m);
};

pd.Print(); 

0 个答案:

没有答案