gdi+问题

alexGIS 2003-10-19 10:10:16
从一个bmp文件载入的Bitmap对象,想要进行剪裁、平移、缩放一类的操作。TranslateTransform不管用。怎么办??
...全文
32 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
MPU 2004-03-05
  • 打赏
  • 举报
回复
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));
}
}
alexGIS 2003-10-20
  • 打赏
  • 举报
回复
楼上,请问怎样才能实现位图的变换呢??
要缩放,要平移等等。
saucer 2003-10-19
  • 打赏
  • 举报
回复
right, TranslateTransform is only for graphic operations like drawing, 剪裁、平移、缩放 involve moving bits around
alexGIS 2003-10-19
  • 打赏
  • 举报
回复
DrawLine等自己绘制的有效果,但是从文件载入的位图就是不动。
saucer 2003-10-19
  • 打赏
  • 举报
回复
are you sure?
Drawing Line Chart in ASP.NET
http://www.c-sharpcorner.com/asp/Code/DrawingChartInASPNetSH.asp

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧