Convert a picture to a 3D image in WPF and rotate it

Source: Internet
Author: User

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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.