我一直试图这样做,但由于某种原因,这只是给我奇怪的结果:
int bpp = Screen.PrimaryScreen.BitsPerPixel;
string fontName = "Tahoma";
Font font = new Font(fontName, 10 * bpp, GraphicsUnit.Point);
Bitmap bm = new Bitmap(20 * bpp, 20 * bpp);
Graphics g = Graphics.FromImage(bm);
TextRenderer.DrawText(g, "a", font, new Rectangle(0, 0, 5 * bpp, 6 * bpp), Color.Black);
g.Flush();
pictureBox1.Image = bm;
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?我没有看到图片上印有任何东西.如果我删除所有bpp引用,我可以看到它,但它非常小.
我想通过从图像创建图形来编辑多页tiff,但是我遇到了错误消息:"无法从具有索引像素格式的图像创建图形对象."
我如何编辑多页tiff?
如果你有一个System.Drawing.Bitmap包含灰度图像的实例,是否有内置的方法用另一种颜色的影响"着色"它?
例如,如果你有咖啡杯的黑白(灰度)图片,并且想要以编程方式创建红色,绿色和紫色版本的单独图像.
有没有人知道讨论GDI +性能的任何可靠(并且希望是广泛的)书籍/网站(超出明显的范围)?
例如,我最近遇到了这个优秀的实验.我最近也注意到这种Graphics.FillPath()方式比方式更快Graphics.DrawPath().我很想知道我缺少的其他重要信息.
亲善,大卫
我想知道如何在C#中绘制矩形并将其拖放到页面中这里我的代码来绘制它但我无法拖放它.
public partial class Form1 : Form
{
public bool drag = false;
int cur_x, cur_y;
Rectangle rec = new Rectangle(10, 10, 100, 100);
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs r)
{
base.OnPaint(r);
Graphics g = r.Graphics;
//g.DrawRectangle(Pens.Black, rec);
g.FillRectangle(Brushes.Aquamarine, rec);
}
private void recmousedown(object sender, MouseEventArgs m)
{
if (m.Button != MouseButtons.Left)
return;
rec = new Rectangle(m.X, m.Y,100,100);
drag = true;
cur_x = m.X;
cur_y = m.Y;
}
private void recmousemove(object sender, MouseEventArgs m)
{
if …Run Code Online (Sandbox Code Playgroud) 如果我System.Drawing.Rectangle在画布和一个上有两个对象,计算哪个( 的任何部分,而不仅仅是它的)最接近那个Point的最佳方法是什么?RectangleRectangleLocation PointPoint
一个单元测试的例子:
Rectangle one = new Rectangle (0, 0, 10, 10);
Rectangle two = new Rectangle (20, 20, 10, 10);
Point point = new Point(14, 14);
Rectangle actual = ClosestToPoint(point, one, two);
// should be closer to one since one's bottom right is at (10, 10)
Assert.That(actual, Is.SameAs(one));
// method to write
public Rectangle ClosestToPoint(Point p, params Rectangle[] rectangles) { }
Run Code Online (Sandbox Code Playgroud) 如何为.net(用于创建.png-images)的微软图表控件创建的图像定义图像分辨率(以DPI为单位).
图表控件的winforms版本具有Chart.RenderingDpi [X | Y] -属性,但是对于asp.net控件,我找不到这样的属性.
有人可以让我找到解决方案吗?
更新
在搜索解决方案期间,我看到图表控件有一个Paint方法.有了这个,我能够用其他DPI设置创建图像.我不确定这是否是正确的方法,但结果对我来说并不坏.我已经发布了代码作为答案.如果有人有更整洁的解决方案,请告诉我.
这是一个非常简单的问题,一直困扰着我,因为几乎每次我编写代码时我都会被绊倒但是这一行.
Bitmap image = Bitmap.FromFile("c:\img.jpg");
Run Code Online (Sandbox Code Playgroud)
我总是直观地假设从FromFile 类中命名的静态方法返回的对象X是类型X.
我意识到,显然我可以回去,Bitmap如果我想要,我确定我错过了一些东西,但根据标题为什么会Bitmap.FromFile(Path)返回一个图像而不是一个Bitmap?这只是一个经过深思熟虑的设计还是在这个实例中返回父类有更基本的原因?
好的,所以我在过去的4个小时内遇到这个bug,我不知道该怎么做..
我正在使用Visual Studio Community 2017,我打开了Consol App(.net core)项目.我也在使用Windows 8.1操作系统.
我想使用System.Drawing命名空间中的Image并且它一直给我错误:"找不到类型或命名空间名称'Image'(你是否缺少using指令或程序集引用?)"
我从https://www.dllme.com/dll/files/system_drawing_dll.html (到桌面)下载了System.Drawing.dll ,然后右键单击右侧项目 - > add-> Reference ..-> Browse ..-> System.Drawing.dll->好的然后我在项目依赖项 - > Assemblies-> System.Drawing的项目中(在解决方案资源管理器中)看到所以我猜它的工作正常吗?!
我仍然得到相同的错误,不能使用System.Drawing命名空间,任何建议?
using System;
using System.Net.Sockets;
using System.Drawing;
namespace client2
{
class Program
{
static void Main(string[] args)
{
try
{
//read image
Image image = new Image("C:\\image\\amir.jpg");
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
我使用System.Drawing和System.Windows.Forms来绘制像素到位图,但我注意到它实际上从来不是一个像素.它更像是3x3点,边缘模糊.我怎样才能绘制一个像素?目前我正在使用bitmap.SetPixel(x, y, color).
F#
open System.Drawing
let bitmap = new Bitmap(256, 256)
for x in 0 .. 255 do
for y in 0 .. 255 do
bitmap.SetPixel(x, y, Color.White)
Run Code Online (Sandbox Code Playgroud)