Mon scénario:
je veux m’attendre à réduire la taille de l’image (10 Ko à 3 Ko)
Eh bien, ce que vous voulez peut être ceci:
// Make sure to include this at the top using System.Drawing.Imaging;
/// /// Saves an image as a jpeg image, with the given quality /// /// Path to which the image would be saved. /// An integer from 0 to 100, with 100 being the highest quality. public static void SaveJpeg (ssortingng path, Image img, int quality) { if (quality<0 || quality>100) throw new ArgumentOutOfRangeException("quality must be between 0 and 100."); // Encoder parameter for image quality EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, quality); // JPEG image codec ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg"); EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = qualityParam; img.Save(path, jpegCodec, encoderParams); } /// /// Returns the image codec with the given mime type /// private static ImageCodecInfo GetEncoderInfo(ssortingng mimeType) { // Get image codecs for all image formats ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); // Find the correct image codec for(int i=0; i
Ensuite, vous pouvez faire ceci:
// First load the image somehow Image myImage = Image.FromFile(pathToImage, true); // Save the image with a quality of 50% SaveJpeg (destImagePath, myImage, 50);
Reportez-vous à cette publication sur les forums VB et à cette publication .
Utiliser GDI
S’il vous plaît regardez cet échantillon. Utilisez GDI + pour redimensionner la photo. Je souhaite que cela puisse vous aider.
Eh bien, les images ne peuvent pas devenir magiquement plus petites, vous devrez donc les compresser ou les réduire.