|
|
|
|
are you sure?
Drawing Line Chart in ASP.NET http://www.c-sharpcorner.com/asp/Code/DrawingChartInASPNetSH.asp |
|
|
|
DrawLine等自己绘制的有效果,但是从文件载入的位图就是不动。
|
|
right, TranslateTransform is only for graphic operations like drawing, 剪裁、平移、缩放 involve moving bits around
|
|
|
|
楼上,请问怎样才能实现位图的变换呢??
要缩放,要平移等等。 |
|
|
public void DrawImageRect4IntAtrribAbortData( )
{ // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback); IntPtr imageCallbackData = new IntPtr(1); // Create image. System.Drawing.Image newImage = System.Drawing.Image.FromFile("D:\\0.png"); Graphics newGraphics = Graphics.FromImage(newImage); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; // Create image attributes and set large gamma. System.Drawing.Imaging.ImageAttributes imageAttr = new System.Drawing.Imaging.ImageAttributes(); imageAttr.SetGamma(1.0F); ///////////////////////////////////////////////////////////// System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(); // 1/3 on the top 3 rows and 3 columns cm.Matrix00 = 1/2f; cm.Matrix01 = 1/2f; cm.Matrix02 = 1/2f; cm.Matrix10 = 1/2f; cm.Matrix11 = 1/2f; cm.Matrix12 = 1/2f; cm.Matrix20 = 1/2f; cm.Matrix21 = 1/2f; cm.Matrix22 = 1/2f; ia.SetColorMatrix(cm); // Draw original image to screen. //newGraphics.DrawImage(newImage, destRect1, x, y, width, height, units, // imageAttr,imageCallback,imageCallbackData); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(0, 0, 150, 150); try { checked { // Create stream. System.IO.MemoryStream MemStream = new System.IO.MemoryStream(); // Create solid brush. SolidBrush whiteBrush = new SolidBrush(Color.White); // Create rectangle. Rectangle[] rects = { new Rectangle( 150, 0, newImage.Size.Width-150, newImage.Size.Height), new Rectangle(0, 150, 150, newImage.Size.Height-150) }; // Fill rectangle to screen. newGraphics.FillRectangles(whiteBrush, rects); /////////////////////////////////////////////////////////////////////////////// /* // Set interpolation mode newGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Rectangle rec = new Rectangle(0, 0, 150, 150); System.Drawing.Region reg = new Region( rec ); newGraphics.Clip = reg; newGraphics.SetClip(rec, System.Drawing.Drawing2D.CombineMode.Replace); // Create rectangle for region. Rectangle excludeRect = new Rectangle(0, 0, 150, 150); // Create region for exclusion. Region excludeRegion = new Region(excludeRect); // Set clipping region to exclude region. newGraphics.ExcludeClip(excludeRegion); // Fill large rectangle to show clipping region. //newGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, 320, 240); */ ///////////////////////////////////////////////////////////////////////////////////// //newImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipX); // Draw adjusted image to screen. newGraphics.DrawImage(newImage,destRect2,x, y,width, height, units,ia,imageCallback,imageCallbackData); //System.Drawing.Bitmap b = new Bitmap(newImage,150,150); newImage.Save(MemStream, System.Drawing.Imaging.ImageFormat.Png);//"D:\\sdfsfs.png" MemStream.WriteTo(Response.OutputStream);//OutputStream Response.OutputStream.Close();//"D:\\CppPNG.png" } } catch (Exception ex) { newGraphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } } |
|