Original: Convert a picture to a 3D image in WPF and rotate it
Time is stolen, is always invisible to us under the eyes of the precious.
Https://pan.baidu.com/s/14dk-OU2SR0nxXj2bL4bVpQ
First look at the original source code to run the effect, whether it is necessary.
Here, the three-dimensional polygon graph is the z-axis data generated by the function, and of course we can use the color of the image as the z axis.
Preparation, VS2008 and above, bloggers use VS2017, need to upgrade the project.
Thank you here: Jianzhong Zhang
Problem:
1, use the color of the picture as the third axis (Z axis)
Solution Ideas:
1.1 See how Z-axis data is generated in the source code
1.2 Read the picture in and convert it into an RGB array
1.3 Replace the image RGB array with the original z-axis data
Find the code in WINDOW1:
1.1 Red indicates that a function is used to assign a value to the z-axis.
//***************************** Convert a picture into a color array *************************** Public Staticsystem.drawing.color[,] Img2color (String imgfile) {System.Drawing.Bitmap img=NewSystem.Drawing.Bitmap (Imgfile); system.drawing.color[,] Allcolor=Newsystem.drawing.color[img. Height, IMG. Width]; for(inth =0; H < img. Height; h++) for(intW =0; W < IMG. Width; w++) {allcolor[h, W]=img. GetPixel (W, h); } GC. Collect (); returnAllcolor;}
Put the following code in the Testsurffaceplot method:
float[] NewData =New float[10000]; system.drawing.color[,] Allcolor= Img2color ("xxx111.jpg"); intwidth = -; for(intj =0; J <10000; J + +) {Color Newcolor=NewColor (); if(allcolor[j% width, j/width]. B < -&& allcolor[j% width, j/width]. R < -&& allcolor[j% width, j/width]. G < -) {Newcolor.a=255; Newcolor.b=255; NEWCOLOR.R=0; NEWCOLOR.G=255; } Else{NEWCOLOR.A= allcolor[j% width, j/width]. A NEWCOLOR.R= allcolor[j% width, j/width]. R NEWCOLOR.G= allcolor[j% width, j/width]. G Newcolor.b= allcolor[j% width, j/width]. B } M_3dchart[j].color=Newcolor; }
Done.
Convert a picture to a 3D image in WPF and rotate it