Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Converting from AI/SVG to PNG with transparent backgrounds.

$
0
0
While I am linking my images, here is one when I use the code like this:
/// <summary>
/// Converts any image to png and uploads it to azure
/// </summary>
/// <param name="data">The byte array of the image</param>
/// <returns>The path to the azure blob</returns>
public async Task<string> ConvertImage(byte[] data, bool replaceBlack)
{

    // Create our image
    using (var image = new MagickImage())
    {
        image.Settings.BackgroundColor = MagickColors.Transparent;

        // Read our image
        image.Read(data);

        // Create a new memory stream
        using (var memoryStream = new MemoryStream())
        {

            // Set to a png
            image.Format = MagickFormat.Png24;
            image.Resize(600, 600);

            // Write to our stream
            image.Write(memoryStream);

            // Reset the memory stream position
            memoryStream.Position = 0;

            // Create a new blob block to hold our image
            var blockBlob = container.GetBlockBlobReference(Guid.NewGuid().ToString() + ".png");

            // Upload to azure
            await blockBlob.UploadFromStreamAsync(memoryStream);

            // Return the blobs url
            return blockBlob.StorageUri.PrimaryUri.ToString();
        }
    }
}
Image

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>