放大后,SVG文件中的图像失去清晰度

时间:2018-10-29 18:11:29

标签: c++ image qt svg qwt

我正在开发一个使用Qt和Qwt框架绘制科学项目图形的应用程序。应用程序需要具有将图表保存为矢量图形格式的SVG文件的功能。这是保存图形的代码。 (顺便说一下,此代码段不是来自我的原始应用程序,而是我编写的用于模拟它的简单测试程序。)

def pos_num():

    # Open num.txt and define num
    num_list = open('num.txt', 'w')
    num = 1

    # While num is positive, ask user for input
    while num >= 0:
        num = int(input('Type + number to add to num_list, - number to end: '))

        # If user input is positive: \
        # convert to str, add to list, convert to int to continue loop
        if num >= 0:
            num = str(num)
            num_list.write(num + '\n')
            num = int(num)

        # If user input is negative: \
        # close num.txt and inform user
        else:
            num_list.close()
            print('List has been written to num.txt')

# Call program 1
pos_num()

# Program 2: Number File Reader
def nfread():

    # Ask user for filename to open
    filename = input('Filename: ')
    infile = open(filename, 'r')

    # Create empty list
    nlist = []

    # Read first line, strip '\n', append to nlist, begin line count
    line = infile.readline()
    line = line.rstrip('\n')
    nlist.append(line)
    count = 1

    # While line is not empty: \
    # read line, strip '\n', append line to nlist, add 1 to count
    while line != '':
        line = infile.readline()
        line = line.rstrip('\n')
        nlist.append(line)
        count += 1
        print(line, count)

    # Close num.txt
    infile.close()

    # Return nlist
    return nlist

乍一看,SVG图像看起来不错且清晰。但是,当我使用Inkscape打开它并以极大的缩放比例放大时,散点图中的点的边界变得模糊。 这是屏幕截图: screenshot of graph after zooming in inkscape

请注意,虽然点的边界失去了清晰度,但左侧的图形注释看起来与原始图像一样好。为了与严格的光栅图形PNG格式进行比较,我尝试将文件保存为PNG格式。当我打开PNG文件并放大时,我发现它们都以低得多的缩放比例分解了。这表明我比纯栅格图形做得更好。但是,我需要找出某种方法使它在放大时看起来更好。这是绘制散点图的代码段(同样来自示例程序)。

QSvgGenerator generator;
generator.setFileName(QString("sample").append(QString::number(rand() % 200)).append(QString(".svg")));
generator.setSize(ui.graphWidget->size());
generator.setViewBox(ui.graphWidget->rect());
generator.setTitle(QString("Sample graph"));

QPainter painter(&generator);
ui.graphWidget->render(&painter);

我可以解决这个问题,还是不可避免?感谢您的关注和时间。

0 个答案:

没有答案