zoukankan      html  css  js  c++  java
  • 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

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

    拼图游戏:略

    颜色:略

  • 相关阅读:
    HDU 1863 畅通工程(Kruskal)
    HDU 1879 继续畅通工程(Kruskra)
    HDU 1102 Constructing Roads(Kruskal)
    POJ 3150 Cellular Automaton(矩阵快速幂)
    POJ 3070 Fibonacci(矩阵快速幂)
    ZOJ 1648 Circuit Board(计算几何)
    ZOJ 3498 Javabeans
    ZOJ 3490 String Successor(模拟)
    Java实现 LeetCode 749 隔离病毒(DFS嵌套)
    Java实现 LeetCode 749 隔离病毒(DFS嵌套)
  • 原文地址:https://www.cnblogs.com/otomii/p/2040837.html
Copyright © 2011-2022 走看看