zoukankan      html  css  js  c++  java
  • Silverlight杂记 图片及WriteableBitmap的使用(画分形1)

    支持的图片格式

    image

    从一个UI中获取为图片

    WriteableBitmap bmp = new WriteableBitmap(SP1, null); 
        img3.Source 
    = bmp;

    7

    画图

    先看效果吧,还是挺漂亮的

    image

    private void Draw() { 
              
    int width = 1024;
              
    int height = 768;
              
    int[] colorTable = new int[256];
              
    for (int i = 0; i < 256; i++) { 
                  Color c 
    = Color.FromArgb( 
                      
    0xFF, (byte)(255 - i), (byte)(255 - i), (byte)(255));
                  colorTable[i] 
    = c.A << 24 | c.R << 16 | c.G << 8 | c.B; 
              }
              WriteableBitmap bmp 
    = new WriteableBitmap(width, height);
              
    for (int x = 0; x < width; x++) { 
                  
    for (int y = 0; y < height; y++) { 
                      
    double zoom = 300
                      
    double x0 = 0double y0 = 0
                      
    double cx = (x - width / 2/ zoom; 
                      
    double cy = (y - height / 2/ zoom;
                      
    int iteration = 0
                      
    int maxIterations = 1000;
                      
    while (x0 * x0 + y0 * y0 <= 4 && iteration < maxIterations) { 
                          
    double xtemp = x0 * x0 - y0 * y0 + cx; 
                          y0 
    = 2 * x0 * y0 + cy; 
                          x0 
    = xtemp;
                          iteration
    ++
                      }
                      
    if (iteration == maxIterations) { 
                          bmp.Pixels[(y 
    * width) + x] = 
                                     colorTable[colorTable.GetUpperBound(
    0)]; 
                      } 
    else { 
                          bmp.Pixels[(y 
    * width) + x] = 
                                     colorTable[iteration 
    % colorTable.Length]; 
                      } 
                  } 
              }
              image2.Source 
    = bmp;
          }

    WriteableBitmap 扩展阅读:

     http://www.cnblogs.com/webabcd/archive/2009/08/27/1554804.html

  • 相关阅读:
    LeetCode-20.Valid Parentheses
    LeetCode-2. Add Two Numbers
    LeetCode-1. Two Sum
    LeetCode Top100 Liked Questions
    位运算
    sublime中文乱码解决办法
    jQuery 参考手册
    jQuery 参考手册
    jQuery 参考手册
    《锋利的Jquery第二版》读书笔记 第三章
  • 原文地址:https://www.cnblogs.com/facingwaller/p/1917063.html
Copyright © 2011-2022 走看看