Application of GDI + in Delphi-Photoshop embossed Effect

Source: Internet
Author: User
The general principle of image relief is to form a difference between each pixel on the image and its diagonal pixel, so that similar color values are reduced and different color values are highlighted, resulting in a vertical depth, to achieve the relief effect, the specific approach is to subtract two pixel values in the diagonal line, plus a background constant, generally 128. This Algorithm Its features are simple and quick, but its disadvantage is that it cannot adjust the angle and depth of the image relief effect.

Using Photoshop to implement image relief effects, you can adjust the relief angle and depth (the distance between two pixels), and adjust the number of pixel differences. The basic algorithm principle is the same as the general relief effect, but the specific method is different: For each pixel to be processed, the position of two corresponding points is calculated according to the relief angle and depth, then, calculate the color value of the two positions and make it form the difference value. Then, multiply the percentage of the difference value in the relief, and add the background color of 128. Note that the two corresponding points calculated here are logical points rather than actual pixels. For example, to implement an image relief effect with a 45 degree angle and a depth of 3, P (x, y). The locations of the two logical points are P0 (X-3*0.7071/2, Y-3*0.7071/2) and p1 (x + 3*0.7071/2, Y + 3*0.7071/2), obviously for such two logical points, it is impossible to find the corresponding pixel from the image directly. If it is simply rounded down, it will produce a large number of identical relief effects formed by different angles and depths, this is not the expected result, and it makes the relief angle and depth parameters lose its original meaning. To this end, the original image must be scaled according to the relief angle and depth, then the relief effect of each pixel is processed, and then the original image size is reduced to complete the relief effect process. The following is the Photoshop embossed effect implementation process I wrote after repeated experiments.Code:

Data Type:

  1. Type
  2. // Image data structure compatible with the GDI + tbitmapdata Structure
  3. Timagedata =Packed Record
  4. Width: longword;// Image Width
  5. Height: longword;// Image Height
  6. Stride: longword;// Scanned line Byte Length
  7. Pixelformat: longword;// Unused
  8. Scan0: pointer;// Image data address
  9. Reserved: longword;// Reserved
  10. End;
  11. Pimagedata = ^ timagedata;
  12. // Obtain the timagedata data structure of the tbitmap image to facilitate the processing of the tbitmap Image
  13. FunctionGetimagedata (BMP: tbitmap): timagedata;
  14. Begin
  15. BMP.Pixelformat: = pf32bit;
  16. Result.Width: = BMP.Width;
  17. Result.Height: = BMP.Height;
  18. Result.Scan0: = BMP.Scanline [BMP.Height-1];
  19. Result.Stride: = Result.WidthSHL 2;
  20. // Result. stride: = (32 * BMP. width) + 31) and $ ffffffe0) SHR 3;
  21. End;

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.