This project is read-only.

Black and White

Aug 1, 2009 at 5:41 PM

Can anyone tell me why my picture is turning out in B&W?

        public void ShrinkPicture(UserControl picture)
        {
            WriteableBitmap bitmap = new WriteableBitmap(picture, null);
            ImageTools.Image image = bitmap.ToImage();
            MemoryStream stream = new MemoryStream();
            JpegEncoder encoder = new JpegEncoder();
            Encode(image, stream);
            EditableProfile.Picture = stream.ToArray();
        }

        // Taken from .NET ImageTools since passing 0 quality leads to DivideByZeroException in fjcore.
        private void Encode(ImageTools.Image image, Stream stream)
        {
            Guard.NotNull(image, "image");
            Guard.NotNull(stream, "stream");
            int width = image.Width;
            int height = image.Height;
            byte[] sourcePixels = image.GetPixels();
            byte[][,] pixels = new byte[3][,];
            for (int b = 0; b < 3; b++)
            {
                pixels[b] = new byte[width, height];
            }
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int offset = ((y * width) + x) * 4;
                    pixels[0][x, y] = sourcePixels[offset];
                    pixels[1][x, y] = sourcePixels[offset];
                    pixels[2][x, y] = sourcePixels[offset];
                }
            }
            ColorModel colorModel = new ColorModel();
            colorModel.ColorSpace = ColorSpace.RGB;
            colorModel.Opaque = false;
            FluxJpeg.Core.Image newImage = new FluxJpeg.Core.Image(colorModel, pixels);
            DecodedJpeg jpg = new DecodedJpeg(newImage);
            new FluxJpeg.Core.Encoder.JpegEncoder(jpg, 100, stream).Encode();
        }

 

Aug 2, 2009 at 8:48 AM

Please take the latest source. All bugs you mentioned are fixed since days:

- Using JpegEncoder results in a Black / White image

- 0 is passed as default quality

- DivideByZeroException (a bug in the fjcore code)

- The requested quality can be passed to the encoder

I want to develop the gif encoder next week and will prepare the next release after completing this task.