小编Mad*_*ads的帖子

如何在 SkiaSharp 中设置调整大小质量

我正在使用 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)

c# image skiasharp asp.net-core-2.2

5
推荐指数
0
解决办法
3583
查看次数

TryUpdateModelAsync 与修改后的值

我使用模型绑定更新数据库,如下所示:

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)

c# asp.net-core-mvc asp.net-core

3
推荐指数
1
解决办法
1995
查看次数

在 C# 中创建 Code128 条形码

我真傻,我以为只要用条形码字体写一些文本,扫描仪就能读取它。看来我错了。

因此,在阅读了一些有关 code128 条形码的文档后,我了解到:

  1. 条形码以(103、104 或 105,取决于类型)开头
  2. 然后是字符串本身
  3. 然后是字符串中每个字符的计算总和乘以其位置的模 103
  4. 然后附加106

我的代码是:

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)

我不确定条形码字符串中应包含多少内容,以便扫描仪读取?: …

c# barcode code128 asp.net-core

3
推荐指数
1
解决办法
1万
查看次数