Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# resize image from byte array

public static byte[] Resize2Max50Kbytes(byte[] byteImageIn)
{
    byte[] currentByteImageArray = byteImageIn;
    double scale = 1f;

    if (!IsValidImage(byteImageIn))
    {
        return null;
    }

    MemoryStream inputMemoryStream = new MemoryStream(byteImageIn);
    Image fullsizeImage = Image.FromStream(inputMemoryStream);

    while (currentByteImageArray.Length > 50000)
    {
        Bitmap fullSizeBitmap = new Bitmap(fullsizeImage, new Size((int)(fullsizeImage.Width * scale), (int)(fullsizeImage.Height * scale)));
        MemoryStream resultStream = new MemoryStream();

        fullSizeBitmap.Save(resultStream, fullsizeImage.RawFormat);

        currentByteImageArray = resultStream.ToArray();
        resultStream.Dispose();
        resultStream.Close();

        scale -= 0.05f;
    }

    return currentByteImageArray;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: get multi-selected rows gridcontrol devexpress 
Csharp :: c# code process to start any exe application 
Csharp :: keyboard hook c# 
Csharp :: How to make a drawer in unity 
Csharp :: inverse kinematics not working unity 
Csharp :: how to dynamically load value in startup file in c# 
Csharp :: embed video to exe file with c# 
Csharp :: select list that does not exis in another C# list 
Csharp :: dinero en C# 
Csharp :: c# switch statement 
Html :: html 5 default code 
Html :: disable spell check html 
Html :: html anchor tag open in new tab 
Html :: bootstrap 4 cdn 
Html :: ion icon size small 
Html :: how to run vscode as root 
Html :: html character tab 
Html :: taka html code 
Html :: html form enctype 
Html :: bootstrap large modal 
Html :: read only html 
Html :: button center bootstrap 
Html :: instagram post iframe 
Html :: how to add a browser tab icon 
Html :: change tab icon html 
Html :: div contenteditable onchange angular 
Html :: bootstrap vertical align 
Html :: angular foreach 
Html :: how to put autoplay music in the background of the page html 
Html :: bootsrap label 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =