标签: system.drawing

System.Drawing.Image.FromStream()方法中的"参数无效"异常

我在网站上使用Image.FromStream方法很难.以下代码在我的计算机上运行良好.但是当我将它上传到测试服务器时,它总是给我"参数无效"异常.

if (!afuImageFile.IsUploading && afuImageFile.HasFile)
{
    System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent);
}
Run Code Online (Sandbox Code Playgroud)

afuImageFileAsynFileUploaderAjax工具包中的一个控件.afuImageFile.FileContent是一个HttpInputStream.我想我需要为某个文件夹添加一些权限.谁能帮我?

c# asp.net system.drawing

6
推荐指数
1
解决办法
8789
查看次数

计算.NET DrawingContext DrawText方法中的文本环绕

我正在开发一个项目,让我近似文本呈现为图像和文本的DHTML编辑器.使用.NET 4 DrawingContext对象的DrawText方法呈现图像.

DrawText方法将文本与字体信息以及尺寸一起使用,并计算使文本尽可能合适所需的包装,如果文本太长则在末尾放置省略号.所以,如果我有以下代码在Rectangle中绘制文本,它将缩写它:

string longText = @"A choice of five engines, although the 2-liter turbo diesel, supposedly good for 48 m.p.g. highway, is not coming to America, at least for now. A 300-horsepower supercharged gasoline engine will likely be the first offered in the United States. All models will use start-stop technology, and fuel consumption will decrease by an average of 19 percent across the A6 lineup. A 245-horsepower A6 hybrid was also unveiled, but no decision has yet …
Run Code Online (Sandbox Code Playgroud)

c# text system.drawing

6
推荐指数
1
解决办法
3896
查看次数

C#在面板上绘图

我正在制定一个日程安排并用面板代表时间段,而约会则是更多的面板.

用户可以向上和向下滚动,以便他们可以看到的范围更早或更晚.当约会在可见范围的末尾运行时,我希望有一个锯齿形,表明约会超出了可见范围.

我已经确定了发生这种情况的情况,并且我调用了一个私有函数drawZigZag(Panel p, int direction);来绘制它.日期水平展开,方向-1表示左侧的锯齿形,1表示右侧的锯齿形.

到目前为止,我还没有达到曲折,我只是在试验CreateGraphics()FillPolygon().到目前为止,我有:

    private void drawZigZag(Panel p, int direction) // 1 = right, -1 = left
    {
        Graphics g = p.CreateGraphics();

        g.FillRectangle(new SolidBrush(Color.FromArgb(0, Color.Black)), p.DisplayRectangle);

        Point[] points = new Point[4];

        points[0] = new Point(0, 0);
        points[1] = new Point(0, p.Height);
        points[2] = new Point(p.Width, p.Height);
        points[3] = new Point(p.Width, 0);

        Brush brush = new SolidBrush(Color.DarkGreen);

        g.FillPolygon(brush, points);
    }
Run Code Online (Sandbox Code Playgroud)

FillRectangle()我最初没有的第一个.我只补充说,当时FillPolygon()没有用.

基本上,它不起作用,我不知道为什么.面板是原始颜色 - 它尚未填充DarkGreen.我以前用过CreateGraphics()其他东西,我不确定为什么它在这种情况下不起作用.有任何想法吗?

编辑:对不起,我想我应该提一下:我的几个Label控件 …

c# system.drawing gdi winforms

6
推荐指数
1
解决办法
5万
查看次数

将文本添加到工具条进度条

我正在尝试将一些文本添加到工具条进度条,但到目前为止我还没有成功,这里是我在这里找到的一些代码:

private void pbPrecentage(ToolStripProgressBar pb)
{
    ProgressBar p = new ProgressBar();

    int percent = (int)(((double)(pb.Value - pb.Minimum) /
    (double)(pb.Maximum - pb.Minimum)) * 100);
    using (Graphics gr = pb.CreateGraphics())
    {
        gr.DrawString(percent.ToString() + "%",
            SystemFonts.DefaultFont,
            Brushes.Black,
            new PointF(pb.Width / 2 - (gr.MeasureString(percent.ToString() + "%",
                SystemFonts.DefaultFont).Width / 2.0F),
            pb.Height / 2 - (gr.MeasureString(percent.ToString() + "%",
                SystemFonts.DefaultFont).Height / 2.0F)));
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是Tool Strip Progress Bar没有CreateGraphics方法.所以我想知道是否有人能够成功地将文本添加到工具条进度条.

UPDATE

好吧,似乎ToolStripProgressBar有一个进度条属性,后者又有CreateGraphics方法,但现在的问题是文本值闪烁并闪烁,我该如何修复它?这是修改后的代码:

private void pbPrecentage(ToolStripProgressBar pb)
{
    int percent = (int)(((double)(pb.Value - pb.Minimum) /
    (double)(pb.Maximum …
Run Code Online (Sandbox Code Playgroud)

c# system.drawing

6
推荐指数
1
解决办法
6605
查看次数

wpf - 我可以在wpf中使用System.Drawing吗?

我将图像保存在数据库中...但如何从数据库中检索该图像..当我尝试使用system.drawing ..它显示一个错误..一些ppl说我不能在wpf中使用system.drwa ..甚至不是dll文件..

我的代码是

private void btnShow_Click(object sender, RoutedEventArgs e)
{
       DataTable dt2 =  reqBll.SelectImage().Tables[0];
       byte[] data = (byte[])dt2.Rows[0][1];
       MemoryStream strm = new MemoryStream();
       strm.Write(data, 0, data.Length);
       strm.Position = 0;
       System.Drawing.Image img = System.Drawing.Image.FromStream(strm);
       BitmapImage bi = new BitmapImage();
       bi.BeginInit();
       MemoryStream ms = new MemoryStream();
       img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
       ms.Seek(0, SeekOrigin.Begin);
       bi.StreamSource = ms;
       bi.EndInit();
       ImgBox.Source = bi;
    }
Run Code Online (Sandbox Code Playgroud)

现在做什么?

我使用了system.drawing.dll ..现在我可以使用system.drawing.bitmap ..但是在使用它之后会在System.Drawing.Image.FromStream(strm)中显示错误;

错误: - 用户代码未处理参数异常

参数无效.

c# wpf system.drawing

6
推荐指数
1
解决办法
2万
查看次数

Powershell 在 System.Drawing 中使用 .NET .DrawImage

我正在制作一个工具,可以自动裁剪和定位,无需将图像大小调整为其他图像。我在 .NET 的微软文档中找到了这个,但我无法理解如何在我的代码中实现。到目前为止,我可以从 Mojang API 下载图像,例如:

Bernd_L.png
Bernd_L.png

史蒂夫.png
史蒂夫

我想知道是否可以在坐标 8,0 处裁剪一个 8x8 像素的矩形1.png并将其粘贴到 Steve.png 顶部坐标 8,8 处,因此最后的输出将如下所示:

输出.png
输出.png

我该如何使用.NET函数.DrawImage来实现裁剪?

编辑

感谢@Caramiriel 提供的链接,我终于可以使用此脚本裁剪图像的区域:

Add-Type -AssemblyName System.Drawing

$Username = "Steve"

$destRect = new-object Drawing.Rectangle 8, 0, 8, 8
$srcRect = new-object Drawing.Rectangle 0, 8, 8, 8
$src=[System.Drawing.Image]::FromFile("$pwd\$Username.png")
$bmp=new-object System.Drawing.Bitmap 64,64
$graphics=[System.Drawing.Graphics]::FromImage($bmp)
$units = [System.Drawing.GraphicsUnit]::Pixel
$graphics.DrawImage($src, $destRect, $srcRect, $units)
$graphics.Dispose()
$bmp.Save("$pwd\output.png")
Run Code Online (Sandbox Code Playgroud)

如果有一种更紧凑/优雅的方法来做到这一点,我真的很想知道!

编辑2

我发布了一个带有通用功能的答案来完成这项工作。

.net powershell system.drawing

6
推荐指数
1
解决办法
9164
查看次数

如何在.NET位图上使用GDI +模糊效果?

我需要对模糊应用System.Drawing.Bitmap.这些类System.Drawing应该是围绕GDI +的包装器,所以我使用GDI + Blur效果.这是可能的,如果是的话,怎么样?

编辑:我不想知道如何编写自己的Blur效果,我想知道如何使用内置的GDI +.

.net c# system.drawing gdi+

5
推荐指数
1
解决办法
7854
查看次数

处理刷子

长时间运行的应用程序存在一些内存问题; 我一直在检查油漆方法,以确保刷子妥善处理.在Brush函数的参数中创建的情况下,刷子会在调用之后被处理吗?

案例概述如下:

     g.DrawString(valueText, Font, new SolidBrush(Color.Red),
Run Code Online (Sandbox Code Playgroud)

.net c# system.drawing winforms

5
推荐指数
1
解决办法
2308
查看次数

如何在执行打印预览时阻止出现"打印进度"对话框

在我的C#应用​​程序中,我正在尝试生成打印预览而屏幕上没有显示进度对话框.

我相信你可以使用PrintDocument.PrintController来打印真实的(即不是打印预览),但是在执行打印预览时它似乎不起作用.

我的代码如下:

public FrmDeliveryNotePrintPreview(DeliveryNote deliveryNote)
{
    InitializeComponent();

    this.Text = "Delivery Note #" + deliveryNote.Id.ToString();


    // The print preview window should occupy about 90% of the
    // total screen height

    int height = (int) (Screen.PrimaryScreen.Bounds.Height * 0.9);


    // Making an assumption that we are printing to A4 landscape,
    // then adjust the width to give the correct height:width ratio
    // for A4 landscape.

    int width = (int) (height / 1.415);


    // Set the bounds of this form. The …
Run Code Online (Sandbox Code Playgroud)

.net c# printing system.drawing

5
推荐指数
2
解决办法
1万
查看次数

将RenderTargetBitmap转换为System.Drawing.Image

我有3D WPF视觉图像,我想传递给Excel单元格(通过剪贴板缓冲区)。

使用“正常” BMP图像,它可以工作,但我不知道如何转换RenderTargetBitmap

我的代码如下所示:

System.Windows.Media.Imaging.RenderTargetBitmap renderTarget = myParent.GetViewPortAsImage(DiagramSizeX, DiagramSizeY);
System.Windows.Controls.Image myImage = new System.Windows.Controls.Image();
myImage.Source = renderTarget;

System.Drawing.Bitmap pg = new System.Drawing.Bitmap(DiagramSizeX, DiagramSizeY);
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(pg);
gr.DrawImage(myImage, 0, 0);

System.Windows.Forms.Clipboard.SetDataObject(pg, true);
sheet.Paste(range);
Run Code Online (Sandbox Code Playgroud)

我的问题是gr.DrawImage不接受a System.Windows.Controls.Image或a System.Windows.Media.Imaging.RenderTargetBitmap;只有一个System.Drawing.Image

如何将转换Controls.Image.Imaging.RenderTargetBitmapImage,或者有没有更简单的方法?

c# wpf system.drawing bitmapimage rendertargetbitmap

5
推荐指数
2
解决办法
8868
查看次数