zoukankan      html  css  js  c++  java
  • WriteableBitmap实现对图片的放大缩小

    xaml:

    <ScrollViewer Name="ScrollViewerName" Background="Transparent" Width="480" Height="480" VerticalScrollBarVisibility="Auto"                         VerticalContentAlignment="Center" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Center">
                        <Image Name="SelectImage" Stretch="None"/></ScrollViewer>

    cs:

       private void ChooserButton_Click(object sender, RoutedEventArgs e)
            {
                PhotoChooserTask task = new PhotoChooserTask();
                task.Completed += new EventHandler<PhotoResult>(task_Completed);
                task.Show();
            }

            private int OriginWidth;
            private int OriginHeight;
            private Image OriginImage;
            void task_Completed(object sender, PhotoResult e)
            {
                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(e.ChosenPhoto);
                OriginImage = new Image();
                OriginImage.Source = bitmap;
                OriginWidth = bitmap.PixelWidth;
                OriginHeight = bitmap.PixelHeight;

                SelectImage.Source = bitmap;
                HeightTextbox.Text = bitmap.PixelHeight.ToString();
                WidthTextbox.Text = bitmap.PixelWidth.ToString();
            }

            private void ReSizeButton_Click(object sender, RoutedEventArgs e)
            {
                double scale_X = Convert.ToDouble(WidthTextbox.Text) / OriginWidth;
                //OriginWidth = Convert.ToInt32(WidthTextbox.Text);//保存本次图片的宽度的pix值
                double scale_Y = Convert.ToDouble(HeightTextbox.Text) / OriginHeight;
                //OriginHeight = Convert.ToInt32(HeightTextbox.Text);//保存本次图片的高度的pix值

                ScaleTransform Scale= SizeAdjust(scale_X, scale_Y);

                WriteableBitmap writebitmap = new WriteableBitmap(OriginImage, Scale);
                //riteableBitmap writebitmap = new WriteableBitmap(SelectImage, Scale);//根据保存上次的长宽值来进行伸缩图片
                writebitmap.Invalidate();
                SelectImage.Source = writebitmap;
            }

            private ScaleTransform SizeAdjust(double x,double y)
            {
                ScaleTransform scale=new ScaleTransform ();
                scale.CenterX=0;
                scale.CenterY=0;
                scale.ScaleX=x;
                scale.ScaleY=y;
                return scale;
            }

  • 相关阅读:
    js四舍五入
    文本框只能输入整数,输入其他的自动不显示
    [转]关于C#程序部署到Android
    ajax在火狐中传中文出现乱码的解决方法
    Vue 记录 Cannot read property '_withTask' of undefined
    vs中 VMDebugger未能加载导致异常
    System.InvalidOperationException: 支持“XXX”上下文的模型已在数据库创建后发生更改。请考虑使用 Code First 迁移更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269)。
    eclipse中将java项目转换成javaweb项目
    Android之SOAP协议与WebService服务器交互,解决超时的问题
    SymmetricDS 快速和灵活的数据库复制
  • 原文地址:https://www.cnblogs.com/mokey/p/2282273.html
Copyright © 2011-2022 走看看