Example #1
0
        private static async Task<ImageAndSource> DecreaseImage(string inputFile)
        {
            var newLenght = maxFileLenght * 3;

            var initialLength = new FileInfo(inputFile).Length;

            var initialImage = await FileToImage(inputFile).ConfigureAwait(false);
            
            while (true)
            {
                using (var scaledImage = new MemoryStream())
                {
                    var scale = Math.Sqrt((((double)newLenght) / initialLength));

                    var transformed = new TransformedBitmap(initialImage, new ScaleTransform(scale, scale));

                    transformed.Freeze();

                    var saver = new JpegBitmapEncoder();

                    saver.Frames.Add(BitmapFrame.Create(transformed));

                    saver.Save(scaledImage);

                    scaledImage.Seek(0, SeekOrigin.Begin);

                    newLenght = newLenght * 4 / 5;

                    if (scaledImage.Length < maxFileLenght)
                    {
                        return new ImageAndSource
                        {
                            image = transformed,
                            source = scaledImage.ToArray()
                        };
                    }
                }
            }
        }
Example #2
0
 public static ImageData CreateFlipped(ImageMetaData info, PixelFormat format, BitmapPalette palette,
                                 byte[] pixel_data, int stride)
 {
     var bitmap = BitmapSource.Create((int)info.Width, (int)info.Height, DefaultDpiX, DefaultDpiY,
                                       format, palette, pixel_data, stride);
     var flipped = new TransformedBitmap(bitmap, new ScaleTransform { ScaleY = -1 });
     flipped.Freeze();
     return new ImageData(flipped, info);
 }
Example #3
0
		private static TransformedBitmap CreateTransformedBitmap(BitmapSource source, VCProfile profile)
		{
			var transformedBitmap = new TransformedBitmap();
			transformedBitmap.BeginInit();
			transformedBitmap.Source = source;
			var transformGroup = new TransformGroup();
			transformGroup.Children.Add(new ScaleTransform(profile.FlipHorizontal ? -1 : 1, profile.FlipVertical ? -1 : 1));
			transformGroup.Children.Add(new RotateTransform(ConvertRotationToDegrees(profile.Rotation)));
			transformedBitmap.Transform = transformGroup;
			transformedBitmap.EndInit();
			transformedBitmap.Freeze();

			return transformedBitmap;
		}
Example #4
0
    private static BitmapSource MetaOrientation(BitmapMetadata meta, BitmapSource ret)
    {
      double angle = 0;
      if ((meta != null) && (ret != null)) //si on a des meta, tentative de récupération de l'orientation
      {
        if (meta.GetQuery("/app1/ifd/{ushort=274}") != null)
        {
          orientation =
            (ExifOrientations)
            Enum.Parse(typeof (ExifOrientations), meta.GetQuery("/app1/ifd/{ushort=274}").ToString());
        }

        switch (orientation)
        {
          case ExifOrientations.Rotate90:
            angle = -90;
            break;
          case ExifOrientations.Rotate180:
            angle = 180;
            break;
          case ExifOrientations.Rotate270:
            angle = 90;
            break;
        }

        if (angle != 0) //on doit effectuer une rotation de l'image
        {
          ret = new TransformedBitmap(ret.Clone(), new RotateTransform(angle));
          ret.Freeze();
        }
      }
      return ret;
    }
Example #5
0
        public static BitmapSource Transform(BitmapSource source, Transform transform)
        {
            if (source == null) throw new ArgumentNullException("source");
            if (transform == null) throw new ArgumentNullException("transform");

            TransformedBitmap target = new TransformedBitmap();
            target.BeginInit();
            target.Source = source;
            target.Transform = transform;
            target.EndInit();
            target.Freeze();

            return CloneImage(target);
        }
        // 静态委托
        public void VideoDataCallbackDelegate(int userId, IntPtr buf, int len, AnyChatCoreSDK.BITMAPINFOHEADER bitMap, int userValue)
        {
            int stride = bitMap.biWidth * 3;
            BitmapSource bs = BitmapSource.Create(bitMap.biWidth, bitMap.biHeight, 96, 96, PixelFormats.Bgr24, null, buf, len, stride);
            // 将图像进行翻转
            TransformedBitmap RotateBitmap = new TransformedBitmap();
            RotateBitmap.BeginInit();
            RotateBitmap.Source = bs;
            RotateBitmap.Transform = new RotateTransform(180);
            RotateBitmap.EndInit();
            RotateBitmap.Freeze();

            // 异步操作
            Action action = new Action(delegate()
            {
                Dispatcher.BeginInvoke(new Action(delegate()
                {
                    if (userId == g_selfUserId)
                        localVideoImage.Source = RotateBitmap;
                    else if (userId == g_otherUserId)
                        remoteVideoImage.Source = RotateBitmap;
                }), null);
            });
            action.BeginInvoke(null, null);
        }