barcodewriter writer = new barcodewriter
{
format = barcodeformat.qr_code,
renderer = new bitmaprenderer
{
foreground = color.black
},
options = new zxing.qrcode.qrcodeencodingoptions
{
disableeci = true,
height = height,
width = width,
margin = 0,
characterset = "utf-8",
errorcorrection = errorcorrectionlevel.m
}
};
bitmap bitmap = writer.write(url);
if (!string.isnullorempty(userface))
{
bitmap bits = (system.drawing.bitmap)system.drawing.image.fromfile(userface);
if (bits != null)
{
//剪裁一个80*80的logo图片
imagecut img = new imagecut(0, 0, 80, 80);
system.drawing.bitmap icon = img.kicut(bits);
//userface_b.jpg是一个边框的图片
bitmap bits2 = new system.drawing.bitmap((system.drawing.bitmap)system.drawing.image.fromfile(application.startuppath + "/user/userface_b.jpg"), 84, 84);
if (icon != null)
{
try
{
//画了2个边框,一个是logo,一个在logo周围加了一个边框
using (var graphics = system.drawing.graphics.fromimage(bitmap))
{
graphics.drawimage(bits2, (bitmap.width - bits2.width) / 2, (bitmap.height - bits2.height) / 2);
graphics.drawimage(icon, (bitmap.width - icon.width) / 2, (bitmap.height - icon.height) / 2);
}
}
catch (exception ex)
{
}
finally
{
icon.dispose();
gc.collect();
}
}
bitmap.save(filename, imageformat.jpeg);
}
}
return bitmap;
}
}
else if (h * width / w < height)
{
intwidth = w * height / h;
intheight = height;
}
else
{
intwidth = width;
intheight = height;
}
bitmap bmpout_b = new system.drawing.bitmap(b, intwidth, intheight);
w = bmpout_b.width;
h = bmpout_b.height;
if (x >= w || y >= h)
{
return null;
}
if (x + width > w)
{
width = w - x;
}
else
{
x = (w-width) / 2;
}
if (y + height > h)
{
height = h - y;
}
try
{
bitmap bmpout = new bitmap(width, height, pixelformat.format24bpprgb);
graphics g = graphics.fromimage(bmpout);
g.drawimage(bmpout_b, new rectangle(0, 0, width, height), new rectangle(x, y, width, height), graphicsunit.pixel);
g.dispose();
return bmpout;
}
catch
{
return null;
}
}
public int x = 0;
public int y = 0;
public int width = 120;
public int height = 120;
public imagecut(int x, int y, int width, int heigth)
{
x = x;
y = y;
width = width;
height = heigth;
}
}
string userurl = string.format("//www.jb51.net/u{0}", userid.trim());
string userface_b = application.startuppath + "/user/" + userid + "_b.jpg";
bitmap bitmap_b = getcodeimgurl(filename_b.replace("_b.", "_b_ewm."), userurl, 400, 400, userface_b);
this.p.image =(system.drawing.image)bitmap_b;
this.p.image.save(filename_b.replace("_b.", "_b_ewm."));
如对本文有疑问, 点击进行留言回复!!
C# 对PDF文档加密、解密(基于Spire.Cloud.SDK for .NET)
Unity通用泛型单例设计模式(普通型和继承自MonoBehaviour)
网友评论