Output graphic

xiaoxiao2021-03-17  198

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 {///

// // Required designer variable. /// private System.ComponentModel.Container components; protected internal System.Windows.Forms.Button button1; private System.Drawing.Brush backgroundBrush; private System.Drawing.Image sample1; private System.Drawing.Image webLogo; private System.Drawing.Image createdImage; private FontFamily serifFontFamily; public ImagesSample () {// // // InitializeComponent Windows form Designer supports required (); serifFontFamily = new FontFamily (GenericFontFamilies.Serif); this.SetStyle ( System.Windows.Forms.ControlStyles.Opaque, true); image backgroundImage; // load the resource from the branch to the executable file for the background image backgroundImage = new Bitmap (System.Reflection.Assembly.GetExecutingAssembly () GetManifestResourceStream (. "Colorbars.jpg")); // Now create a brush BackgroundbrushBrushBrushBrushBrush = new textimage; // now load other images you want to use SAMPLE1 = New bitmap ("sample.jpg"); // load an image from the web and display it.

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);}} ///

/// clean all resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = null) {components.dispose ();}} Base.Dispose (Disposing);} /// /// Designer supports the necessary methods, do not use the /// code editor to modify the contents of this method. /// void InitializeComponent () {this.components = new System.ComponentModel.Container (); this.button1 = new System.Windows.Forms.Button (); this.Size = new System.Drawing.Size (750, 500); this.Text = "GDI brush example"; Button1.TabINDEX = 0; button1.text = "Picture to file"; button1.size = new system.drawing.size (100, 50) Button1.Location = new system.drawing.point (600, 20); this.controls.add (button1);} /// /// The primary entry point of the application. /// [stathread] public static void main () {Application.run (new imagessample ());}}

<% @ 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:

转载请注明原文地址:https://www.9cbs.com/read-129717.html

New Post(0)