• WP7备注(35)(Vector Graphics|Raster Graphics)


    Vector Graphics Pass

    --------------------------------------------------------------------------------------------------

    Raster Graphics:

    image

    BitmapSource拥有2个字段,1个方法:

    PixelWidth,PixelHeight
    SetSource(Stream stream)

    BitmapImage拥有2个字段,3个事件来记录图片加载过程:

    UriSource,CreateOptions

    WriteableBitmap:

    WriteableBitmap writeableBitmap = new WriteableBitmap(element, transform);
    transform可以为null

    writeableBitmap.Render(element, transform);

    writeableBitmap.Invalidate();重新绘制Bitmap

    PhotoChooserTask photoChooser = new PhotoChooserTask();
    public MainPage()
    {
    InitializeComponent();
    photoChooser.Completed += OnPhotoChooserCompleted;
    }
    protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
    {
    int dimension = (int)Math.Min(ContentPanel.ActualWidth,
    ContentPanel.ActualHeight) - 8;
    photoChooser.PixelHeight = dimension;
    photoChooser.PixelWidth = dimension;
    photoChooser.Show();
    args.Complete();
    args.Handled = true;
    base.OnManipulationStarted(args);
    }
    void OnPhotoChooserCompleted(object sender, PhotoResult args)
    {
    if (args.Error != null || args.ChosenPhoto == null)
    return;
    BitmapImage bitmapImage = new BitmapImage();
    bitmapImage.SetSource(args.ChosenPhoto);
    Image imgBase = new Image();
    imgBase.Source = bitmapImage;
    imgBase.Stretch = Stretch.None;
    // Upper-left
    WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth /
    2,
    bitmapImage.PixelHeight /
    2);
    writeableBitmap.Render(imgBase, null);
    writeableBitmap.Invalidate();
    imgUL.Source = writeableBitmap;
    // Upper-right
    writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth / 2,
    bitmapImage.PixelHeight / 2);
    TranslateTransform translate = new TranslateTransform();
    translate.X = -bitmapImage.PixelWidth / 2;
    writeableBitmap.Render(imgBase, translate);
    writeableBitmap.Invalidate();
    imgUR.Source = writeableBitmap;
    // Lower-left
    writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth / 2,
    bitmapImage.PixelHeight / 2);
    translate.X = 0;
    translate.Y = -bitmapImage.PixelHeight / 2;
    writeableBitmap.Render(imgBase, translate);
    writeableBitmap.Invalidate();
    imgLL.Source = writeableBitmap;
    // Lower-right
    writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth / 2,
    bitmapImage.PixelHeight / 2);
    translate.X = -bitmapImage.PixelWidth / 2;
    writeableBitmap.Render(imgBase, translate);
    writeableBitmap.Invalidate();
    imgLR.Source = writeableBitmap;
    txtblk.Visibility = Visibility.Collapsed;
    }

    CircularGradient:

    const int RADIUS = 200;
    public MainPage()
    {
    InitializeComponent();
    WriteableBitmap writeableBitmap = new WriteableBitmap(2 * RADIUS, 2 *
    RADIUS);
    for (int y = 0; y < writeableBitmap.PixelWidth; y++)
    for (int x = 0; x < writeableBitmap.PixelHeight; x++)
    {
    if (Math.Sqrt(Math.Pow(x - RADIUS, 2) + Math.Pow(y - RADIUS, 2)) <
    RADIUS)
    {
    double angle = Math.Atan2(y - RADIUS, x - RADIUS);
    byte R = (byte)(255 * Math.Abs(angle) / Math.PI);
    byte B = (byte)(255 - R);
    int color = 255 << 24 | R << 16 | B;
    writeableBitmap.Pixels[y * writeableBitmap.PixelWidth + x] =
    color;
    }
    }
    writeableBitmap.Invalidate();
    img.Source = writeableBitmap;
    }

    image

    ----------------------------------------------

    拼图游戏:略

    颜色:略

  • 相关阅读:
    Hadoop 2.7 伪分布式环境搭建
    Linux 安装配置 Tomcat
    Hadoop hdfs完全分布式搭建教程
    Hadoop中ssh+IP、ssh+别名免秘钥登录配置
    VMware 克隆多台Linux机器并配置IP
    Linux 安装JDK
    连表更新数据
    设置让php能够以root权限来执行exec() 或者 shell_exec()
    Jsonp 关键字详解及json和jsonp的区别,ajax和jsonp的区别
    php7安装mongoDB扩展
  • 原文地址:https://www.cnblogs.com/otomii/p/2040837.html
Copyright © 2020-2023  润新知