调整数据网格视图单元格中的位图图像的大小

本文关键字:位图 图像 单元格 数据 数据网 网格 视图 调整 | 更新日期: 2023-09-27 18:32:22

仍然有调整图像大小的问题。

使用 c sharp.net 4.0 winforms 和 MS Visual Studio 2010。

这是我目前拥有的代码:

private void ShowArrow()
    {
        foreach (DataGridViewRow paretoRow in ParetoGrid.Rows)
        {
            if ((paretoRow.Cells["Pareto6"].Value != null) && (Convert.ToInt32(paretoRow.Cells["CurrentPareto"].Value) < (Convert.ToInt32(paretoRow.Cells["NewPareto"].Value))))
            {
                downArrow.Width = 2; 
                downArrow.Height = 2;
                paretoRow.Cells["p1"].Value = downArrow; 
            }
            else if ((paretoRow.Cells["Pareto6"].Value != null) && (Convert.ToInt32(paretoRow.Cells["CurrentPareto"].Value) > (Convert.ToInt32(paretoRow.Cells["NewPareto"].Value))))
            {
                //ParetoGrid.Rows[paretoRow.Index].DefaultCellStyle.BackColor = Color.LightGreen;
                paretoRow.Cells["p1"].Value = upArrow;
            }
        }
    }

但是当我尝试编辑图像大小时,它说图像是只读的?这是调整图像大小的好一行吗? 还是有更好的方法?

非常感谢

调整数据网格视图单元格中的位图图像的大小

您可以检查图像对象的"只读"属性并继续执行它。假设你的变量是 BitmapImage myImage。

bool isReadOnly = myImage.IsSealed;

还有另一种称为 SetValue 的方法。希望这有帮助。

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx

如果你

有一个 Image 对象,你可以试试这个:

http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx

实际上不是单行解决方案,但它已经接近它。您可能希望事先生成调整大小的图像,并在以后使用它。