Exemplo n.º 1
0
        public void loadFromStream(Stream stream)
        {
            size = stream.Length;

            if (JPEG.test(stream))
            {
                _img = new JPEG(stream);
                type = JPEG.MIME;
                ((JPEG)_img).extractHeaders();                 // preserve headers for later
                meta = ((JPEG)_img).metaInfo();

                // save thumb data as Blob
                object thumbData;
                if (meta.ContainsKey("thumb") && ((Dictionary <string, object>)meta["thumb"]).TryGetValue("data", out thumbData))
                {
                    Blob blob = new Blob(new List <object> {
                        (byte[])thumbData
                    }, new Dictionary <string, string> {
                        { "type", "image/jpeg" }
                    });
                    Moxie.compFactory.add(blob.uid, blob);
                    ((Dictionary <string, object>)meta["thumb"])["data"] = blob.ToObject();
                }
            }
            else if (PNG.test(stream))
            {
                _img = new PNG(stream);
                type = PNG.MIME;
            }
            else
            {
                Error(this, new ErrorEventArgs(ImageError.WRONG_FORMAT));
                return;
            }

            Dictionary <string, int> info = _img.info();

            if (info != null)
            {
                width  = info["width"];
                height = info["height"];
            }

            BitmapImage bitmapImage = new BitmapImage();

            bitmapImage.SetSource(stream);
            _bm = new WriteableBitmap(bitmapImage);

            Load(this, null);
        }
Exemplo n.º 2
0
        public void loadFromStream(Stream stream)
        {
            size = stream.Length;

            if (JPEG.test(stream))
            {
                _img = new JPEG(stream);
                type = JPEG.MIME;
                ((JPEG)_img).extractHeaders();                 // preserve headers for later
                meta = ((JPEG)_img).metaInfo();
            }
            else if (PNG.test(stream))
            {
                _img = new PNG(stream);
                type = PNG.MIME;
            }
            else
            {
                throw new ImageError(ImageError.WRONG_FORMAT);
            }

            Dictionary <string, int> info = _img.info();

            if (info != null)
            {
                width  = info["width"];
                height = info["height"];
            }

            BitmapImage bitmapImage = new BitmapImage();

            bitmapImage.SetSource(stream);
            _bm = new WriteableBitmap(bitmapImage);

            Load(this, null);
        }