我正在使用 SkiaSharp 调整现有图像的大小。在调整大小时,我希望能够在不同级别上测试/设置质量。
这是我的代码:
public static class ResizeImage {
public static string Resize(string image, int maxWidth = 0, int maxHeight = 0, int quality = 90, bool copy = false) {
var bitmap = SKBitmap.Decode(image);
if (bitmap.Width > maxWidth || bitmap.Height > maxHeight)
{
int width;
int height;
var extension = Path.GetExtension(image);
SKEncodedImageFormat imageFormat = GetImageFormat(extension);
if (imageFormat != SKEncodedImageFormat.Astc)
{
if (bitmap.Width >= bitmap.Height)
{
width = maxWidth;
height = Convert.ToInt32(bitmap.Height * maxWidth / (double)bitmap.Width);
}
else
{
width …Run Code Online (Sandbox Code Playgroud) 我使用模型绑定更新数据库,如下所示:
var adminUpdate = await _context.Admins.FindAsync(Id);
if (!String.IsNullOrEmpty(Password)) {
if (Password != PasswordCheck) {
ModelState.AddModelError("Password", "Passwords do not match");
} else {
byte[] data = Encoding.UTF8.GetBytes(Password + Configuration["SomeLocation:SomeKey"]);
data = SHA512.Create().ComputeHash(data);
password = Convert.ToBase64String(data);
}
} else {
password = adminUpdate.Password;
}
if (!ModelState.IsValid) {
return Page();
}
if (await TryUpdateModelAsync(
adminUpdate,
"",
a => a.FirstName,
a => a.LastName,
a => a.Email,
a => a.Password, // must be the value of "password"
a => a.Status,
a => a.CompanyId
))
{ …Run Code Online (Sandbox Code Playgroud) 我真傻,我以为只要用条形码字体写一些文本,扫描仪就能读取它。看来我错了。
因此,在阅读了一些有关 code128 条形码的文档后,我了解到:
我的代码是:
public string Str = "MADS";
public string Barcode = null;
public void OnGet()
{
int start = 104;
int end = 106;
int calc = start;
Barcode = start.ToString();
for (var i = 0; i < Str.Length; i++)
{
calc += (Convert.ToChar(Str[i]) - 32) * (i + 1);
Barcode += Str[i];
}
double rem = calc % 103;
Barcode += Convert.ToChar((int)rem + 32).ToString() + end;
Console.WriteLine(Barcode);
}
Run Code Online (Sandbox Code Playgroud)
我不确定条形码字符串中应包含多少内容,以便扫描仪读取?: …