自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

用Silverlight 3的位圖API實現(xiàn)可寫位圖

原創(chuàng)
開發(fā) 后端
Silverlight 3 這次帶來的全新位圖API令圖像處理更加便捷。本文介紹了通過Silverlight 3 的 WriteableBitmap 類創(chuàng)建圖像的思路方法。

【51CTO快譯】Silverlight 3 這次帶來的全新位圖API實現(xiàn)了如下的三個首要目標:

◆從無到有創(chuàng)建位圖,以像素為單位

◆在客戶端處理從服務(wù)器或本地加載的圖像

◆從視覺樹到位圖的分區(qū)渲染,以達成類似于截屏的功能(另外,預(yù)渲染和緩存元素有時也能起到提高性能的作用)

從無到有創(chuàng)建位圖

創(chuàng)建位圖的關(guān)鍵在于System.Windows.Media.Imaging下的WriteableBitmap類。運用此類可以創(chuàng)建一個預(yù)先分配到普通圖像元素上的源。

﹤Grid x:Name="LayoutRoot"﹥
﹤Image x:Name="MyBitmap"
Width="200"
Height="200" /﹥
﹤/Grid﹥

以下提供的代碼可以實現(xiàn)一些很有趣的圖形效果。

private void BuildBitmap()
{
const int imageWidth = 200;
const int imageHeight = 200;

WriteableBitmap b =
new WriteableBitmap(imageWidth, imageHeight,
PixelFormats.Bgr32);

b.Lock();


for (int x = 0; x ﹤ imageWidth; x++)
{
for (int y = 0; y ﹤ imageHeight; y++)
{
// generate a color in Pbgra32 format
byte[] components = new byte[4];
components[0] = (byte)(x % 255); // blue
components[1] = (byte)(y % 255); // green
components[2] = (byte)(x * y % 255); // red
components[3] = 0; // unused

// you could certainly do your own masking here
int pixelValue = BitConverter.ToInt32(components, 0);

// set the pixel value
b[y * imageWidth + x] = pixelValue;
}
}

b.Invalidate();
b.Unlock();

MyBitmap.Source = b;

}

最終成品如下:

可以明顯看出,以上代碼經(jīng)歷了四個流程:鎖定,寫入,無效化,解鎖。這是WPF兼容所需要的。

你也可以修改一個現(xiàn)有的位圖,并渲染該位圖的內(nèi)容控件。

原文:Silverlight 3 – The Bitmap API / WriteableBitmap

作者:Pete Brown

【編輯推薦】

  1. 微軟發(fā)布Silverlight 3首個Beta版
  2. 見微知著 Silverlight 3與Flash橫向比較
  3. Silverlight 3將支持3D圖像和硬件加速
責(zé)任編輯:yangsai 來源: 51CTO.com
相關(guān)推薦

2009-12-29 16:21:46

silverlight

2013-04-02 13:56:12

UI線程處理位圖

2021-08-27 22:07:55

Oracle索引位圖

2010-04-07 17:56:49

Oracle位圖索引

2009-04-10 14:38:17

Oracle高手位圖索引

2010-04-08 10:57:04

Oracle編程

2013-05-21 10:42:48

Android游戲開發(fā)Bitmap位圖旋轉(zhuǎn)

2022-04-14 10:19:40

系統(tǒng)應(yīng)用技術(shù)

2018-08-20 10:40:09

Redis位圖操作

2017-08-30 10:32:30

云計算大會展位圖

2017-05-09 09:36:52

Android App高效顯示位圖

2022-03-29 08:18:32

位圖算法索引技術(shù)

2024-06-26 08:00:00

2021-08-27 10:19:28

工具代碼開發(fā)

2009-06-25 09:00:43

Silverlight

2009-02-02 10:53:34

SilverlightSilverlightRIA

2009-11-18 11:33:23

Silverlight

2009-06-15 10:00:08

FluorineFx庫Silverlight

2009-12-03 16:22:32

2021-06-17 09:36:07

鴻蒙HarmonyOS應(yīng)用
點贊
收藏

51CTO技術(shù)棧公眾號