namespace Microsoft.Samples.WinForms.Cs.GDIPlus.GDIPImages {using System; using System.Windows.Forms; using System.IO; using System.Net; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing. Imaging; using system.drawing.text; using system.reflection; public class imagessample: system.windows.forms.form {///
If this fails, the image is loaded try {WebRequest request = WebRequest.Create ( "http://www.microsoft.com/net/images/bnrWindowsNgws1.gif") from the local resource; request.Credentials = CredentialCache.DefaultCredentials; Stream source = Request.getResponse (). getResponseStream (); memorystream ms = new memoryStream (); byte [] data = new byte [256]; int c = source.read (data, 0, data.length); while (c> 0) {ms.write (data, 0, c); c = source.read (data, 0, data.length);} Source.close (); ms.position = 0; WebLogo = New Bitmap (MS); } catch (exception) {// messagebox.show ("Failed to load images from the Web - Please use the default image / n / n" EX.MESSAGE "/ N / N" EX.STACKTRACE, "Error") WebLogo = Sample1;} / / Start the event handler button1.click = new system.eventhandler (DrawImage);} // excitation private void DrawImage (object sender, EventArgs e) {Bitmap newBitmap = null when the button is pressed; Graphics g = null; try {newBitmap = new Bitmap (800,600, PixelFormat.Format32bppArgb); g = Graphics.FromImage (newBitmap) ; g.FillRectangle (new SolidBrush (Color.White), new Rectangle (0,0,800,600)); Font textFont = new Font (serifFontFamily, 12); RectangleF rectangle = new RectangleF (100, 100, 250, 350); string flowedText = "I went to the St. James Hospital, / n to visit my lover, / n her flat on a white table,
/ n is so sweet, so cold, then beautiful, / n let her go, let her go, may God bless her, / n, no matter where she go, / n can overlook this vast world, / N But she will never find a good man like me, / n When I die, I hope you give me a neat system, / n I want to wear a straight coat, wear a wide side hat , / N placed a $ 20 gold coin on my chain, / n This boys will know that I am standing.
"; G.FillRectangle (new SolidBrush (Color.Gainsboro), rectangle); g.DrawString (flowedText, textFont, new SolidBrush (Color.Blue), rectangle); Pen penExample = new Pen (Color.FromArgb (150, Color. Purple, 20); penexample.dashstyle = dashstyle.dash; penexample.startcap = linecap.Round; penexample.endcap = linecap.Round; g.drawcurve (penexample, new point [] {new Point (200, 140), new Point (700, 240), New Point (500, 340), New Point (140, 140), New Point (40, 340),}; NewbitMap.Save ("Testimage.png", ImageFormat.png); MessageBox .Show ("Completed - Image has been written to testimage.png"); // Add image created and redrawed = newbitMap; this.invalidate ();} finally {/ / Note: You must dispose of graphic objects // before disposing this bitmap //, you need to dispose of IF (NULL! = G) when the created // graphic object is needed, {g.dispose ();} / / Usually here to place this bitmap // but because we intend to display it on the form / /, do not do // if (null! = Newbitmap) {// newbitmap.dispose (); //} }} protected override void OnPaint (PaintEventArgs e) {Graphics g = e.Graphics; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // // fill the background crude brush with white paint and then apply g.FillRectangle (backgroundBrush, ClientRectangle);
G. FillRectangle (New Solidbrush (color.fromargb (180, color.white)), clientRectangle); // Just render image G.DrawImage (Sample1, 29, 20, 283, 212); // Now rotate the image and Show it g.RotateTransform (-30); g.drawImage (WebLogo, 175, 420); g.RsetTransform (); // Finally, draw (if there is an image) if (CreatedImage! = Null) {g.drawImage (CreatedImage, 50, 200, 200, 200);}} ///
<% @ Page language = "vb" debug = "true"%> <% @ import namespace = "system.drawing"%> <% @ import namespace = "system.drawing.imaging"%> <% @ import namespace = "System.drawing.drawing2d"%> <'' '' '' '' '' '' '' '' '' '' '' '' '' Lets ASP.NET Output Graphics. Dim StrfileName AS. "DIM STRFILENAME AS String 'declared variable, used for image path DIM I as system.drawing.image' creation .NET frame image processing object instance DIM IMGG1 AS INTEGER = CINT (INT (6 * RND ()) 1)) 'Generate 1- 6 Random number DIM OYDJ AS STRING = IMGG1STRFILENAME = "D: / O123 /" Oydj ". Jpg" 'loaded image path, here Oydj represents randomly generated variables for generating random pictures i = system.drawing .Image.fromfile (Strfilename) Dim b as new system.drawing.bitmap (i.Width, I.Height, Pixelformat.format24bpprgb) Dimg AS graphics = graphics.fromimage (b) g.clear (color.blue) 'Background Color is blue 'Teaching with example, go to the bar learning channel [http://123.xia8.com] DIM SSS = Request.ServerVariables ("remote_addr") G.DrawImage (i, new point (0, 0))' Here, it means that a character, the 9th Song body is thick white, Pointf (160, 50) is the coordinate of the screen G. DrawString (SSS, New Font ("Song", 9, FontStyle.Bold, New Solidbrush (Color.White ), New Pointf (160, 50)) G. DrawString (SSS, New Font ("Song", 9, FO NTStyLE.BOLD), New Solidbrush (Color.White), New Pointf (161, 51)) Response.ContentType = "image / jpeg" 'Specifying the output format is graphic B.Save (Response.OutputStream, Imageformat.jpeg) B. Dispose ()%>
Third article: