Asp. NET Image special effects processing

Source: Internet
Author: User
Tags net set background client
Asp.net| Special effects general graphics processing including graphics amplification, graphics, graphics, rotation and stretching effect. In this section, we learn to use GDI + to handle these operations through an instance.

Create a new Web Form named Gdi_sample5.aspx, and the logical code in GDI_Sample5.aspx.vb is as follows:

'------Code BEGIN-----

'--omitting namespace references

Public Class Gdi_sample5

Inherits System.Web.UI.Page

#Region the code generated by the Web Forms Designer

' Omit the code generated by the form designer here

#End Region

Private Sub Page_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load

' The user code to place the initialization page here

Dim I as Int16

Dim B as Bitmap

b = New Bitmap (300, 1000)

' Declare Graphics object

Dim G as Graphics

' Specify the canvas

g = Graphics.fromimage (b)

' Set background color to black

G.clear (Color.Black)

Dim img as Drawing.image

img = Drawing.Image.FromFile (Server.MapPath (".") & "/test.jpg")

' Original artwork

g.DrawString ("= Original =-", New Font ("XXFarEastFont-Arial", FontStyle.Bold), Brushes.white, New PointF (80, 2))

G.drawimage (IMG, M, IMG). Width, IMG. Height)

' Enlarge

G.drawline (New Pen (Color.White, 1), 10, 165, 280, 165)

g.DrawString ("= magnified twice times Figure =-", New Font ("XXFarEastFont-Arial,", FontStyle.Bold), Brushes.white, New PointF (80, 168))

G.drawimage (IMG, 190, CInt (IMG). Width * 1.4), CInt (IMG). Height * 1.4))

' Shrink

G.drawline (New Pen (Color.White, 1), 10, 410, 280, 410)

g.DrawString ("= shrink 1/twice times Figure =-", New Font ("XXFarEastFont-Arial,", FontStyle.Bold), Brushes.white, New PointF (80, 415))

G.drawimage (IMG, 435, CInt (IMG). width/1.4), CInt (IMG). height/1.4))

' Stretch

G.drawline (New Pen (Color.White, 1), 10, 775, 280, 775)

g.DrawString ("= Stretch effect =-", New Font ("XXFarEastFont-Arial", FontStyle.Bold), Brushes.white, New PointF (80, 780))

G.drawimage (IMG, 795, IMG). Width +, IMG. HEIGHT-50)

' Rotate

G.drawline (New Pen (Color.White, 1), 10, 560, 280, 560)

g.DrawString ("= Rotate 90 degrees =-", New Font ("XXFarEastFont-Arial", FontStyle.Bold), Brushes.white, New PointF (80, 565))

Img. RotateFlip (Rotatefliptype.rotate90flipnone)

G.drawimage (IMG, 590, IMG). Width, IMG. Height)

' Export to the client browser, because the picture that ASP.net draws uses the security color, therefore can cause the eclipse when viewing in the browser

B.save (Response.outputstream, Drawing.Imaging.ImageFormat.Gif)

' Save as a test1.jpg file in the physical path directory of the Web application

B.save (Server.MapPath (".") & "/test1.jpg")

End Sub

End Class

'-----code End--------

After you save the compilation, the results are shown in Figure 11.5.


Figure 11.5 Gdi_sample5.aspx Run Results

Because the image that is exported to the client browser is displayed in a safe color, the image is dimmed while browsing through the browser, but the image saved on the hard disk is the primary color and will not be eclipsed.

11.6 Summary of this chapter

This chapter briefly introduces the method of drawing graphics using GDI + technology. GDI + is a new graphics Desktop Engine, is an application programming interface, GDI + is a high-level encapsulation class for GDI. The Graphics object is the only reserved object in a drawing operation. The ability to generate graphics in. NET is encapsulated in the System.Drawing namespace, which supports a variety of graphics file formats, including: JPEG, GIF, PNG, TIFF, BMP, PhotoCD, FlashPIX, WMF, EMF, and EXIF. The use of bitmap objects and graphics objects can easily achieve some simple graphics processing requirements. Of course, GDI + technology drawing graphics function is not a chapter can be detailed, this chapter is a brief introduction, not the focus of the book, interested readers can refer to the relevant special books. In the next chapter we will learn about the safety control knowledge of asp.net.



Related Article

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.