发生的事情(仅在某些图像上会引人注目)是我会看到1像素的白色边框插入一个像素.它似乎发生在轻而不是白色的区域(例如天空).它类似于某些东西过度锐化并且在高对比度边缘旁边可以看到鬼影边框.
这是完美再现它的repro代码.我正在使用所有最高质量的设置进行缩放.
ImageCodecInfo encoder = null;
EncoderParameters encoderParams = null;
foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders())
{
if (codec.MimeType == "image/jpeg")
{
encoder = codec;
// use highest quality compression settings
encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
break;
}
}
using (Bitmap input = (Bitmap)Bitmap.FromFile(inputPath, true))
{
// shrink by multiple of 2
Rectangle rect = new Rectangle(0, 0, input.Width/32, input.Height/32);
using (Bitmap output = new Bitmap(rect.Width, rect.Height))
{
using (Graphics g = Graphics.FromImage(output))
{
// use highest …Run Code Online (Sandbox Code Playgroud) 有很多关于渲染高质量图形的帖子,比如这个
我需要使用GDI +在图形中渲染大约6k +对象(线和椭圆),帧速率大约为10fps.所以我的图形需要最低质量的属性.
这是我做的:
public static class GraphicsExtensions
{
public static void ToHighQuality(this Graphics graphics)
{
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
}
public static void ToLowQuality(this Graphics graphics)
{
graphics.InterpolationMode = InterpolationMode.Low;
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.SmoothingMode = SmoothingMode.HighSpeed;
graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
}
}
Run Code Online (Sandbox Code Playgroud)
我忘记了什么,或者这是图形属性的最佳极值?
我使用较低模式绘制5fps(202ms /图像),使用较高模式绘制3fps(330ms /图像).
我觉得没有太大的区别,但是我把性能问题减少到只画画......
一些数字:
我在c#中缩小图像,并且我将我的方法与Photoshop cs5中的最佳方法进行了比较,并且无法复制它.
在PS我使用bicubic锐化,看起来非常好.但是,当尝试在c#中做同样的事情时,我得不到高质量的结果.我尝试了双三次插值以及HQ双三次,平滑模式HQ /无/ AA.合成模式,我尝试了大约50种不同的变化,每种变化都非常接近右边的图像.
你会注意到她背面和标题周围的像素化,以及作者的名字不太好.
(左边是PS,右边是c#.)

似乎c#bicubic即使平滑设置为无,也会进行太多平滑处理.我一直在玩下面代码的许多变体:
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.None;
g.SmoothingMode = SmoothingMode.None;
Run Code Online (Sandbox Code Playgroud)
编辑:这里要求的是起始图像(1mb).

我的程序:包含一个包含少量文本框和一个按钮的表单."默认打印机" 在我的计算机上设置为Adobe PDF.
我的目标:当用户点击"打印"按钮时,想要截取表单/ usercontrol的屏幕截图.然后屏幕截图以.pdf格式保存在桌面上.
我的问题:我在代码中遇到两个问题:
问题1:程序捕获的屏幕截图在打印时不适合页面.

我希望截图图像在.pdf的一页上适合这样:

码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Text = "Print Form";
button1.Click += new EventHandler(button1_Click);
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
this.Controls.Add(button1);
}
private void button1_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
Bitmap memoryImage;
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics …Run Code Online (Sandbox Code Playgroud) 我有两个重叠的图片框.两个图片框的图像都有一些透明像素.我想通过重叠图片框的透明像素看到底部图片框.
我尝试将两个图片框的背景颜色设置为透明.但它只是将图片框的背面颜色设置为表单的背景颜色.
嗨,我已经加载了位图,我需要设置自己的高度和宽度,
bitmap.height = 100;
Run Code Online (Sandbox Code Playgroud)
但这句话不允许我,因为它说的
'System.Drawing.Image.Width' cannot be assigned to -- it is read only
Run Code Online (Sandbox Code Playgroud)
什么方法重新调整位图的大小?或者分配这些参数?
我从这里找到了一篇关于图像处理的文章:http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing一切正常.
我希望在调整图像大小时保持高质量.我想如果我能提高DPI值,我就可以做到这一点.有谁知道这是否可能?如果是这样,我如何在C#中实现它?
我正在寻找一个类(用c#)检查我的图像大小(宽度和高度)(或图像大小以kb为单位),如果它们与我喜欢的尺寸不匹配,请调整它们的大小(意味着使用约束和相对宽度和高度新大小像在photoshop图像大小=所以我们不会丢失图像外观)
这项工作有很多课程,但哪一个更好?
谢谢你的未来发展
我想知道,一旦我将图像加载到窗体中,有没有办法允许用户拖动该图像的角落并重新调整大小?
目前,我知道PictureBox.Scale方法(但不推荐使用).我也知道PictureBox.Image.Size.这是否意味着每次重新调整大小时我都需要使用PictureBox.Image.Size?另外,我如何允许他们抓取图像以重新调整大小?我想我正在考虑绘画以及它如何允许用户选择图像,然后通过拖动角来重新调整大小......
我不是在寻找一个完整的解决方案 - 只是在正确方向上的一些指针(伪代码或一般描述来帮助我的思维过程会很好).我不太确定如何解决这个问题.
到目前为止,这是我的代码:
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Load Image";
if (ofd.ShowDialog() == DialogResult.OK)
{
PictureBox pictureBox = new PictureBox();
pictureBox.Image = new Bitmap(ofd.FileName);
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox.Size = pictureBox.Image.Size;
panelArea.Controls.Add(pictureBox);
}
}
Run Code Online (Sandbox Code Playgroud) 我已经阅读了这个问题,高质量图像缩放库,但它只适用于GDI +.
当我缩小Image我的应用程序时,它变得非常锯齿状.
我无法在Image课堂上找到任何允许我提高缩小质量的属性.
我怎样才能做到这一点?
编辑:
我现在使用了这段代码:
BitmapImage img = new BitmapImage();
img.UriSource = new Uri(Graphic, UriKind.Relative);
return img;
Run Code Online (Sandbox Code Playgroud)
哪个Graphic是string包含图像路径的,但是我得到了这个异常:
Weather.DLL中出现"System.ArgumentException"类型的异常,但未在用户代码中处理
附加信息:给定的System.Uri无法转换为Windows.Foundation.Uri.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=215849.
据我所知,Windows.Foundation.Uri在.net框架中没有使用.
那么为什么它会给我这个错误呢?
我有一个 asp.net/C# 类,它调整图像大小以作为文件缓存在服务器上,但是确定使用哪个编码器的代码部分似乎偶尔会抛出 NullReferenceException。
这是初始化并传回编码器的代码:
public static class ImageUtilities{
private static Dictionary<string, ImageCodecInfo> encoders = null;
public static Dictionary<string, ImageCodecInfo> Encoders{
get{
if (encoders == null){
encoders = new Dictionary<string, ImageCodecInfo>();
}
//if there are no codecs, try loading them
if (encoders.Count == 0){
foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders()){
encoders.Add(codec.MimeType.ToLower(), codec);
}
}
return encoders;
}
}
...
Run Code Online (Sandbox Code Playgroud)
这是抛出异常的特定行:
encoders.Add(codec.MimeType.ToLower(), codec);
Run Code Online (Sandbox Code Playgroud)
这是错误文本:
Object reference not set to an instance of an object.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at …Run Code Online (Sandbox Code Playgroud)