Wednesday, September 19, 2012

How to crop and compress an bitmap file and load it as a Meta File

    Bitmap croppedImage = bitmap.Clone(new Rectangle(0, top, bitmap.Width, limit - top), bitmap.PixelFormat);
    System.Drawing.Image cha = image;
    Graphics g = null;                                    
    ImageCodecInfo imageCodecInfo = null;
    System.Drawing.Imaging.Encoder encoder;
    EncoderParameter encoderParameter;
    EncoderParameters encoderParameters;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for (int j = 0; j < encoders.Length; ++j)
        if (encoders[j].MimeType == "image/tiff")
            imageCodecInfo = encoders[j];
    encoder = System.Drawing.Imaging.Encoder.Compression;
    encoderParameters = new EncoderParameters(1);
    encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionLZW);
    encoderParameters.Param[0] = encoderParameter;
    string path = this.TempFileName("tif");
    croppedImage.Save(path, imageCodecInfo, encoderParameters);
    System.Drawing.Image m = Metafile.FromFile(path);

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...