gdi+问题

alexGIS 2003-10-19 10:10:16
从一个bmp文件载入的Bitmap对象,想要进行剪裁、平移、缩放一类的操作。TranslateTransform不管用。怎么办??
...全文
34 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
【图书描述】: GDI+是新一代的图形接口。如果要设计.NET Framework图形应用程序,就必须使用GDI+。本书是一本为.NET开发人员讲授如何编写Windows和Web图形应用程序的专著,书中全面介绍了GDI+和Windows图形程序设计的基本知识和GDI+图形程序设计的各个方面。 本书适合于开发GDI+图形应用程序的初、中级程序员阅读,书中给出了大量用C#语言编写的可重用示例代码,可以使读者更快地掌握书中所介绍的各种知识和概念。本书也可以作为大专院校相关课程的重要辅导教材。 【编辑推荐】: 《GDI+图形程序设计》是为.NET开发人员介绍如何编写Windows和Web图形应用程序的指南用书。通过大量详尽的实例,本书使有经验的程序员可以更深入地理解在.NET Framework类库中定义和整个GDI+API。   本书从介绍GDI+Windows图形程序设计的基本知识开始,其核心是对一些实际问题的指导,包括如何使用Windows Forms及如何优化GDI+的性能。本书通过一些例子来说明如何开发真实世界的工具,如GDI+Painter、GDI+Editro、ImageViewer和ImageAnimator等。另外,作者还给出了大量使用C#语言编写的可重用示例代码,读者可从网上下载完整的C#和Visual Basic.NET源代码,并可通过这些源代码查看书中各图的彩色效果 第1章 GDI+ ——下一代图形接口 1.1 理解GDI+ 1.2 探索GDI+ 的功能 1.3 从GDI的角度学习GDI+ 1.4 .NET中的GDI+ 名称空间和类 总结 第2章 第一个GDI+ 应用程序 2.1 绘制表面 2.2 坐标系统 2.3 指南——第一个GDI+ 应用程序 2.4 一些基本的GDI+ 对象 总结 第3章 Graphics类 3.1 Graphics类的属性 3.2 Graphics类的方法 3.3 GDI+ Painter应用程序 3.4 绘制饼图 总结 第4章 使用画笔和钢笔 4.1 理解和使用画笔 4.2 在GDI+ 中使用钢笔 4.3 使用钢笔进行变形 4.4 使用画笔进行变形 4.5 系统钢笔和系统画笔 4.6 一个真实世界的例子 ——在GDI+ Painter应用程序中添加颜色、钢笔和画笔 总结 第5章 颜色、字体和文本 5.1 访问Graphics对象 5.2 使用颜色 5.3 使用字体 5.4 使用文本和字符串 5.5 渲染文本的质量和性能 5.6 高级版式 5.7 一个简单的文本编辑器 5.8 文本变形 总结 第6章 矩形和区域 6.1 Rectangle结构体 6.2 Region类 6.3 区域和剪辑 6.4 剪辑区域示例 6.5 区域、非矩形窗体和控件 总结 第7章 图像处理 7.1 光栅图像和矢量图像 7.2 使用图像 7.3 操作图像 7.4 在GDI+ 中播放动画 7.5 使用位图 7.6 使用图标 7.7 扭曲图像 7.8 绘制透明的图形对象 7.9 查看多个图像 7.10 使用图片框查看图像 7.11 使用不同的大小保存图像 总结 第8章 高级图像处理 8.1 渲染位图的一部分 8.2 使用图元文件 8.3 使用颜色对象应用颜色映射 8.4 图像属性和ImageAttributes类 8.5 编码器参数与图像格式 总结 第9章 高级二维图形 9.1 线帽和线条样式 9.2 理解并使用图形路径 9.3 图形容器 9.4 读取图像的元数据 9.5 混合 9.6 Alpha混合 9.7 其他高级二维主题 总结 第10章 变形 10.1 坐标系统 10.2 变形的类型 10.3 Matrix类与变形 10.4 Graphics类与变形 10.5 全局变形、局部变形和复合变形 10.6 图像变形 10.7 颜色变形和颜色矩阵 10.8 图像处理中的矩阵操作 10.9 文本变形 10.10 变形顺序的重要性 总结 第11章 打印 11.1 简要地回顾使用Microsoft Windows进行打印的历史 11.2 打印过程概述 11.3 第一个打印应用程序 11.4 打印机的设置 11.5 PrintDocument和Print事件 11.6 打印文本 11.7 打印图形 11.8 打印对话框 11.9 自定义页面设置 11.10 打印多个页面 11.11 页边打印——注意事项 11.12 进入细节——自定义控制和打印控制器 总结 第12章 开发GDI+ Web应用程序 12.1 创建第一个ASP.NET Web应用程序 12.2 第一个图形Web应用程序 12.3 绘制简单的图形 12.4 在Web上绘制图像 12.5 绘制曲线图 12.6 绘制饼图 总结 第13章 GDI+ 的最佳实践及性能技术 13.1 理解渲染过程 13.2 双缓存和无抖动绘图 13.3 理解SetStyle方法 13.4 绘图过程的质量与性能 总结 第14章 GDI互操作性 14.1 在受控环境中使用GDI 14.2 在受控代码中使用GDI的注意事项 总结 第15章 其他GDI+ 示例 15.1 设计交互式GUI应用程序 15.2 绘制具有形状的窗体和Windows控件 15.3 为绘制的图像添加版权信息 15.4 从流或数据库读取及写入图像 15.5 创建自绘制的列表控件 总结 附录A .NET中的异常处理

62,041

社区成员

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

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

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

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