Почему делает изменение размеров изображения png, теряют прозрачность?

Согласно документу monday.com , этот API обновит ровно один столбец. URL включает в себя имя столбца. Похоже, вам нужно два отдельных звонка.


Второй $put_fields= перезаписывает содержимое первого $put_fields=. Так что к тому времени, когда дело доходит до завитков, нет 'column_id' => 'email.

Один из подходов может быть следующим: сделать сам массив column_id таким, как

column_id => ['email' : theemail, 'phone': 5555555]

Очевидно, что для этого потребуются изменения в curl_setopt($ch, CURLOPT_POSTFIELDS, $put_fields);.

Другой вариант, перечислить ключи отдельно в массиве $put_fields. Не ясно, зачем вам нужен column_id, так как он не используется.

10
задан Shog9 15 April 2009 в 22:27
поделиться

3 ответа

Your code doesn't do quite what you think that it does...

You use the GetThumbnailImage to resize the image, then you draw the thumbnail image into itself which is rather pointless. You probably lose the transparency in the first step.

Create a blank bitmap instead, and resize the source image by drawing it on the blank bitmap.

private byte[] GetThumbNail(string imageFile) {
  try {
    byte[] result;
    using (Image thumbnail = new Bitmap(160, 59)) {
      using (Bitmap source = new Bitmap(imageFile)) {
        using (Graphics g = Graphics.FromImage(thumbnail)) {
          g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
          g.InterpolationMode =  System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
          g.DrawImage(source, 0, 0, 160, 59);
        }
      }
      using (MemoryStream ms = new MemoryStream()) {
        thumbnail.Save(ms, ImageFormat.Png);
        thumbnail.Save("test.png", ImageFormat.Png);
        result = ms.ToArray();
      }
    }
    return result;
  } catch (Exception) {
    throw;
  }
}

(I removed some parameters that were never used for anything that had anything to do with the result, like the imageLen parameter that was only used to create a byte array that was never used.)

25
ответ дан 3 December 2019 в 14:11
поделиться

Попробуйте использовать вызов .MakeTransparent () для вашего растрового объекта.

9
ответ дан 3 December 2019 в 14:11
поделиться

May be you should do something like this because this thing worked for me:

String path = context.Server.MapPath("/images");
if (!path.EndsWith("\\"))
    path += "\\";
path += "none.png";

Image img = CreateThumbnail(Image.FromFile(path));

MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Png);
ms.WriteTo(context.Response.OutputStream);

private System.Drawing.Image CreateThumbnail(System.Drawing.Image i)
{
    int dWidth = i.Width;
    int dHeight = i.Height;
    int dMaxSize = 150;

    if (dWidth > dMaxSize)
    {
        dHeight = (dHeight * dMaxSize) / dWidth;
        dWidth = dMaxSize;
    }
    if (dHeight > dMaxSize)
    {
        dWidth = (dWidth * dMaxSize) / dHeight;
        dHeight = dMaxSize;
    }
    return i.GetThumbnailImage(dWidth, dHeight, delegate() { return false; }, IntPtr.Zero);
}
2
ответ дан 3 December 2019 в 14:11
поделиться
Другие вопросы по тегам:

Похожие вопросы: