• 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

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

    拼图游戏:略

    颜色:略

  • 相关阅读:
    Arraw function
    constructor&object 的联系与对比
    for each in&for in&for of
    编程历史
    正则表达式
    DOM&BOM
    关于码云0095的一篇文章。
    vue2路由导航守卫(钩子函数)
    原声ajax请求数据
    express 创建项目
  • 原文地址:https://www.cnblogs.com/otomii/p/2040837.html
Copyright © 2020-2023  润新知