小编taj*_*i01的帖子

在C#中无失真的裁剪和打印图像文档

我正在使用WinForms.在我的表格中,我有一个用于显示图像文档的图片框.问题是当我裁剪图像然后打印文档时图像变得稍微扭曲.如果我不裁剪图像文档并定期打印,图像文档不会变形.

如何裁剪和打印图像文档而不会使图像文档失真?

或者是否有更好的方法来编码,以便它可以裁剪和打印而不会使图像文档失真?如果是这样,我该怎么办?

笔记:

  • 我的图片框设置为缩放,因为我使用的图像很大:

  • 图像文档示例尺寸:2500 x 3100

  • 我的图片框没有边框

    int _cropX, _cropY, _cropWidth, _cropHeight;
    public Pen _cropPen;
    private State _currentState;
    
    private enum State
    {
        Crop
    }
    
    private void Open_btn_Click(object sender, EventArgs e)
    {
        // open file dialog 
        OpenFileDialog open = new OpenFileDialog();
    
        if (open.ShowDialog() == DialogResult.OK)
        {
            // display image in picture box
            pictureBox1.Image = new Bitmap(open.FileName);
        }
    }
    
    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        try
        {
            if (Crop_Checkbox.Checked == true)
            {
                Cursor = Cursors.Default;
                if (_currentState == State.Crop) …
    Run Code Online (Sandbox Code Playgroud)

.net c# printing picturebox winforms

14
推荐指数
1
解决办法
855
查看次数

使用Bootstraps输入字段样式和JQuery功能

我正在使用BootstrapJQuery UI,我似乎偶然发现了一个问题.我在Bootstrap中设计了大部分代码.我试图实现一个年龄验证对话框" 验证:如果一个人不到18岁就做某事......".我设法用JQuery实现了年龄检查验证.接下来,我想让输入字段看起来像bootstraps输入字段,因为我的主窗体中的所有输入字段看起来都像bootstraps输入字段.我怎么能做到这一点?

      $(document).ready(function () {
        $("#age").datepicker({
            onSelect: function(value, ui) {
                var current = new Date().getTime(), 
                    dateSelect = new Date(value).getTime();
                    age = current - dateSelect;
                    ageGet = Math.floor(age / 1000 / 60 / 60 / 24 / 365.25); // age / ms / sec / min / hour / days in a year
                if(ageGet < 18){
                    less_than_18(ageGet);
                }
            },
            yearRange: '1900:+0d',//base year:current year
            changeMonth: true,
            changeYear: true,
            defaultDate: '-18yr',
        }).attr("readonly", "readonly"); //prevent manual changes


        function …
Run Code Online (Sandbox Code Playgroud)

html css jquery bootstrap-modal

13
推荐指数
1
解决办法
252
查看次数

在100毫秒内查看大型多页Tif图像

我正在使用WinForms.在我的表单中,我有一个pictureBox(设置为normal mode),下一个和上一个按钮.我想快速调整大小和加载多页TIF图像.当我转到多页TIF图像的下一页时,每次将图像绘制到图像时都会遇到延迟pictureBox.图像的平均速度大约需要800毫秒.我希望页面在100毫秒内加载.

我希望像IrfanView一样快速处理大型TIF图像.IrfanView是一个小型图像查看应用程序.如果您下载IrfanView,您可以看到性能有多快.目前我有另一个解决方案,我使用多线程后台工作程序将TIF页面加载到一个数组然后我缩小它.这种方法最初需要一些时间,但这里的目标是不必等待.

有没有办法提高Graphics.DrawImage.NET中大图像的性能?

g.DrawImage(img,0,0,width,height); //此行导致延迟"800毫秒,具体取决于您的计算机"

  • 我使用的TIF图像的大小:宽度= 16800,高度= 10800
  • 只有黑白Tif图像
  • 位深度= 1
  • 分辨率单位= 2

在此输入图像描述

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Diagnostics;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;

namespace Tif_Preformance_Question
{
public partial class Form1 : Form
{

    int counter = -1;
    int frameCount = 0;
    Stopwatch s = new Stopwatch();
    Image img;
    Image[] images;

    public Form1()
    {
        InitializeComponent();
    }

    private void btn_Open_Click(object …
Run Code Online (Sandbox Code Playgroud)

.net c# image winforms image-resizing

11
推荐指数
1
解决办法
1146
查看次数

以编程方式打开位于C#中的计算机中的Word文档

我正在使用WinForms.我有一个有按钮的表单.

目标:点击按钮:打开word文档.将文件路径硬编码到程序中的位置.我不希望用户必须找到word文档.

问题:我收到此错误消息.当我编写代码时,我在"应用程序"下面出现了一个红色错误行.

在此输入图像描述

    private void button1_Click(object sender, EventArgs e)
    { 
        this.Application.Documents.Open(@"C:\Test\NewDocument.docx", ReadOnly:true)

    }
Run Code Online (Sandbox Code Playgroud)

.net c# file winforms

7
推荐指数
4
解决办法
3万
查看次数

使用.tif图像进入下一页时提升性能

我正在使用WinForms.在我的表格中,我有一个打开和下一个按钮.我的应用程序将.tif图像打开到图片框中..tif我使用的所有图像都有多个页面.下一个按钮用于转到tif图像中的下一页..tif我使用的这些图像非常大.

示例:尺寸:2600 x 3300(.tif图像)

问题:如何优化应用程序的性能?我已阅读/研究过我可能需要直接从计算机内存和其他一些方法加载图像.我将如何解决这个问题,还是有更好的编码方式?

这是我到目前为止的代码,但是当我进入下一页时,我的应用程序有点滞后.你能帮帮我吗?

下面是一个包含多个页面的大型tif图像的链接,供测试.

链接

http://www.filedropper.com/tiftestingdoc

    FileStream _stream;
    Image _myImg; // setting the selected tiff
    string _fileName;


    private Image _Source = null;
    private int _TotalPages = 0;

    private int intCurrPage = 0;

    private void Clone_File()
    { // Reads file, then copys the file and loads it in the picture box as a temporary image doc. That way files are not locked in users directory when …
Run Code Online (Sandbox Code Playgroud)

.net c# image picturebox winforms

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

使用IEnumerable.Except

我在WinForm中获得了3 listViews2 textbox和2 buttons.

程序说明:程序listview通过在数字中输入数字textbox并单击添加来添加数字button

目标:我希望能够使用该IEnumerable.Except方法仅输出唯一数字listView3,例如在下图中唯一数字是3和7 in listView1listView2.ListViewItem lvi = new ListViewItem(textBox1.Text); listView1.Items.Add(LVI);

ListViewItem lv = new ListViewItem(textBox2.Text);
listView2.Items.Add(lv);

//im doing somthing wrong here...
var nonintersect = listView1.Except(listView2).Union(listView2.Except(listView1));

//populate listview3 with the unique numbers...
// foreach (item )
// {

// }
Run Code Online (Sandbox Code Playgroud)

错误消息:System.Windows.Forms.ListView'不包含'Except'的定义,并且没有扩展方法'Except'可以找到接受类型'System.Windows.Forms.ListView'的第一个参数(你错过了吗?使用指令或程序集引用?)

在此输入图像描述

.net c# ienumerable except

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

从picturebox C#打印高质量的Tiff文档

我正在使用 WinForms。我的程序将 .Tiff 图像文档打开到一个图片框中。我遇到的问题是从图片框打印高质量的 tiff 图像。我已经多次尝试和测试过打印。当文档打印时,文字不清晰/清晰,有点模糊。我还测试了我的打印机,以检查我的打印机是否有问题。我使用 Microsoft Word 打印了一个普通的文本文档,并且打印的很清楚,所以我的代码有问题。

有人可以向我提供在我的图片框中打印高质量 .tiff 图像的代码吗?我是否需要以编程方式增加 DPI 以提高图像质量?

在此处输入图片说明

这是我的代码。

    private void DVPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {

        e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        e.Graphics.DrawImage(pictureBox1.Image, 25, 25, 800, 1050);

    }


    private void Print_button_Click(object sender, EventArgs e)
    {
        PrintPreviewDialog.Document = PrintDocument;
        PrintPreviewDialog.ShowDialog();
    }
Run Code Online (Sandbox Code Playgroud)

在进一步分析我的代码后,我想我明白了为什么我的图片变得模糊。当我打开 Tiff 文档时,我的表单中有多个 tiff 页面的后退和前进按钮。在 RefreshImage 方法中,我认为这就是我的图像变得模糊的地方。这是我的代码:

    private int intCurrPage = 0; // defining the current page (its some sort of a counter)
    bool opened = false; // if an image was opened

    //-------------------------------------Next and Back Button------------------------------------------------- …
Run Code Online (Sandbox Code Playgroud)

.net c# printing image picturebox

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

自定义GroupBox,带有自定义TextColor,BorderColor和Transparent BackColor

我正在使用WinForms.在我的形式我有一个GroupBox.这是一个自定义组框.我想要一个透明的背景groupbox.我遇到问题创建透明背景groupbox问题这个代码是我在将组框设置backcolor为透明时继续出错.

错误:控件不支持透明背景颜色.

g.Clear(BackColor = Color.Transparent); (这是给我问题的那条线)

    private void DrawGroupBox(GroupBox box, Graphics g, Color textColor, Color borderColor)
    {
        if (box != null)
        {
            Brush textBrush = new SolidBrush(textColor);
            Brush borderBrush = new SolidBrush(borderColor);
            Pen borderPen = new Pen(borderBrush);
            SizeF strSize = g.MeasureString(box.Text, box.Font);
            Rectangle rect = new Rectangle(box.ClientRectangle.X,
                                           box.ClientRectangle.Y + (int)(strSize.Height / 2),
                                           box.ClientRectangle.Width - 1,
                                           box.ClientRectangle.Height - (int)(strSize.Height / 2) - 1);

            // Clear text and border
            g.Clear(BackColor …
Run Code Online (Sandbox Code Playgroud)

.net c# transparency groupbox winforms

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

使用按钮向右和向左移动面板单击C#

我正在使用WinForms.在我的表格中,我有一个带按钮的面板可以移动面板.例如,向上和向下按钮可向上或向下移动面板.我在使用相应的按钮左右移动面板时遇到困难.我做错了什么?

    private void Up_btn_Click(object sender, EventArgs e)
    {
        if (panel1.Location.Y > -2000) 
        {
            panel1.Location = new Point(panel1.Location.X, panel1.Location.Y - 80);        
        }
    }

    private void Down_btn_Click(object sender, EventArgs e)
    {
        if (panel1.Location.Y < 720) 
        {
            panel1.Location = new Point(panel1.Location.X, panel1.Location.Y + 80);
        }
    }

    private void Left_btn_Click(object sender, EventArgs e)
    {
        if (panel1.Location.X < 720) 
        {
            panel1.Location = new Point(panel1.Location.Y , panel1.Location.X + +55);             
        }
    }

    private void Right_btn_Click(object sender, EventArgs e)
    {
        if (panel1.Location.X < 720) 
        {
            panel1.Location = new …
Run Code Online (Sandbox Code Playgroud)

.net c# move panel winforms

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

使用数组按顺序获取文件

我正在使用 WinForms。在我的表单中,我有一个文本框,在其中放置文件路径以查看该特定文件夹中的文件。问题是我的数组索引对文件的排序与我在文件夹中看到的不同。如何使我的数组与我在文件夹中看到的内容相匹配?

    private void Button_Click(object sender, EventArgs e)
    {
      string[] array1 = Directory.GetFiles(img_Source_TxtBox.Text);
    }
Run Code Online (Sandbox Code Playgroud)
  • 请注意,我的数组索引是来自该特定目录的随机索引。

数组值

在此输入图像描述

我的文件夹值

在此输入图像描述

.net c# arrays file winforms

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