Flash makes a very realistic magnifying glass

Source: Internet
Author: User
Tags filter
Amplification

Let's talk about the realization of the idea and principle bar: Magnifying glass everyone has used, right? In fact, the implementation of the flash inside the big mirror is nothing more than a large area to show a small part of the area, so that is the magnifying glass in the pixel map to the original image of a small portion. Of course, if this small part is bigger than the magnifying glass itself, it becomes a shrink mirror.

First, let's take a look at the pixel mapping section of the code first.

var _dfilter:displacementmapfilter = new Displacementmapfilter (a bitmap mapping parameter, new Point (0,0), 1,2,0,0);

Yes, in Flash we can use the Displacementmapfilter filter to do pixel mapping, the previous one to do another effect Bump Mapping also use this filter, we know that the filter is powerful. It must be strange to see this function, how does pixel mapping use a graph as a mapping parameter? This is because usually when making graphics, they prefer to use the image as a parameter transmission, so that an array of parameters as a map transfer to the graphics card. This is the map we passed in.

Another advantage of using pictures as a parameter is that you can visually see the shape of these parameter distributions. How does this mapping map come to be resolved? In fact, we know that a true color of the pixel has a 32bit, is the ARGB, any one of the channels to occupy 8-bit width, you can represent any number 0-255. In the Displacementmapfilter class, he reads this graph and then reads the pixels of the X and Y axes in a predetermined 2 channels, and then looks for them on the target map, bingo, to find the color. The specific forms are as follows:

Dstpixel[x, Y] = srcpixel[x + ((componentx (x, y)-128) * ScaleX)/256, Y + ((componenty (x, y)-128) * ScaleY)/256]

Here, I have given this displacemapfilter a picture. This picture in the middle part of the image to enlarge the average, and near the edge is a very exaggerated amplification, the final effect of the 2 can be downloaded in the system. After using a displacementmapfilter, we can get a very simple magnifying glass effect, but sometimes we want to have something interesting, such as the magnification of the refractive index of the magnifying glass, This way we can see through the magnifying glass some of the edges of the object has a true refraction effect, I believe in daily life you must have encountered these conditions. In fact, the refraction effect is very simple, in fact, is the original image of the R,g,b channel separate, and then to them using the magnifying glass we said earlier, and the magnification of these magnifying glass to make a little adjustment, such as 1.5,1.6,1.7. Finally, we stack up to three channels using Add rendering mode. The following is a comparison chart that uses and does not use a prism effect.

With Prism effect

You may ask where the map is from, in fact, the graph is another flash generated by me .... Then I cut a picture, edit edit, in the guide to Flash, very dirt, as for the specific implementation, you can go to see my code.



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.