VII. Diffusion
Move the color values of random points within the range of xoffset and yoffset to the current position for display. Another way is to move the current vertex to another position for display. P1 + Stride * Yin + Xin * 3 is the offset calculation method. 1 Public Static Bool Diffuse (Bitmap B, Int Xoffset, Int Yoffset, Int Step)
2 {
3 Bitmapdata bmdata = B. lockbits ( New Rectangle ( 0 , 0 , B. Width, B. Height ),
4 Imagelockmode. readwrite, pixelformat. format24bpprgb );
5 Int Stride = Bmdata. stride;
6 System. intptr scan0 = Bmdata. scan0;
7 Unsafe
8 {
9 Byte * P = ( Byte * )( Void * ) Scan0;
10 Byte * P1 = P;
11 Int Noffset = Stride - B. Width * 3 ;
12 Random Rad = New Random ();
13 For ( Int Y = 0 ; Y < B. height; ++ Y)
14 {
15 For ( Int X = 0 ; X < B. width; ++ X)
16 {
17 If (Y % Step = 0 && X % Step = 0 )
18 {
19 Int Xin = Rad. Next ( 2 * Xoffset) - Xoffset + X;
20 Int Yin = Rad. Next ( 2 * Yoffset) - Yoffset + Y;
21 If (Xin < 1 ) Xin = 0 ;
22 Else If (Xin > B. Width - 1 ) Xin = B. Width - 1 ;
23 If (Yin < 1 ) Yin = 0 ;
24 Else If (Yin > B. Height - 1 ) Yin = B. Height - 1 ;
25 Byte * Ptemp = P1 + Stride * Yin + Xin * 3 ;
26 P [ 0 ] = Ptemp [ 0 ];
27 P [ 1 ] = Ptemp [ 1 ];
28 P [ 2 ] = Ptemp [ 2 ];
29 }
30 P + = 3 ;
31 }
32 P + = Noffset;
33 }
34 }
35 B. unlockbits (bmdata );
36 Return True ;
37 }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service