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

  • 相关阅读:
    iOS开发UI篇—懒加载
    iOS开发UI篇—简单的浏览器查看程序
    iOS开发UI篇—transframe属性(形变)
    iOS开发UI基础—手写控件,frame,center和bounds属性
    iOS开发UI篇—Button基础
    Foundation框架—集合
    Foundation框架—字符串
    Foundation框架—结构体
    ios 工程配置统一增加类的前缀(知识点也只能算知识点)
    Runtime 函数 Swizzling 改变OC方法的调度顺序
  • 原文地址:https://www.cnblogs.com/facingwaller/p/1917063.html
Copyright © 2011-2022 走看看