我正在嘗試將我的草圖匯出為 pdf。我遇到的問題是,由于某種原因,我的草圖只有一部分匯出為 pdf,就好像原始草圖被裁剪了一樣!當我運行我的草圖時,會出現 64 條線(按預期),實際上當我將它保存為 png 時,所有 64 條線都在那里,并且草圖看起來與我運行它時的一樣。
但是,當我將草圖匯出為 pdf 時,只顯示 16 行,就好像 pdf 正在裁剪我的草圖并且只匯出裁剪的部分。
這是顯示草圖應該是什么樣子的 png:

這是pdf匯出的內容:

這是我的代碼:
import processing.pdf.*;
import java.util.Random;
int cols, rows;
int videoScale = 100;
boolean recordPDF = false;
void setup() {
size(800,800);
pixelDensity(2);
frameRate(0.5);
cols = width/videoScale;
rows = height/videoScale;
}
void draw() {
if (recordPDF) {
beginRecord(PDF, "pdfs/" str(random(1000)) ".pdf");
}
background(255);
strokeWeight(1.5);
drawLines();
if (recordPDF) {
endRecord();
recordPDF = false;
println("Printed pdf.");
}
}
void keyPressed() {
if (key == 'p') {
recordPDF = true;
}
if (key == 's') {
saveFrame("img.png");
}
}
void drawLines() {
// Begin loop for columns
for (int i = 0; i < cols; i ) {
// Begin loop for rows
for (int j = 0; j < rows; j ) {
int x = i*videoScale;
int y = j*videoScale;
line(x,y,x 30,y 30);
}
}
}
我查看了有關 PDF 匯出的相關檔案,但找不到解決方案。任何幫助將不勝感激!
uj5u.com熱心網友回復:
從 setup() 中洗掉 pixelDensity(2) 進行修復。PixelDensity 為 2 旨在允許視網膜顯示幕使用所有像素。如果必須使用它,則需要為 pdf 檔案撰寫單獨的 drawLines()(示例如下)。請注意,對于 pdf drawLines(),videoScale 被減半,每條線的第二組 x,y 坐標是 15 而不是 30。您還必須更改保存的每個檔案的路徑,以使其適合您的系統。我使用了不同的方法從 pGraphics 創建 pdf,這應該無關緊要。
/*
If pixelDensity(2) is used, need to modify second drawLines() for pdf.
Change file paths to suit your system.
*/
import processing.pdf.*;
import java.util.Random;
int cols, rows;
int videoScale = 100;
void drawLines() {
for (int i = 0; i < cols; i ) {
for (int j = 0; j < rows; j ) {
int x = i*videoScale;
int y = j*videoScale;
strokeWeight(1.5);
line(x, y, x 30, y 30);
}
}
}
void setup() {
size(800, 800);
background(255);
pixelDensity(2);
// frameRate(0.5);
cols = width/videoScale;
rows = height/videoScale;
drawLines();
}
void draw() {
}
void keyPressed() {
if (key == 'p') {
PGraphics pdf = createGraphics(width, height, PDF, "/Users/me/Desktop/output.pdf"); // change this
videoScale = 50; // cut in half
pdf.beginDraw();
for (int i = 0; i < cols; i ) {
for (int j = 0; j < rows; j ) {
int x = i*videoScale;
int y = j*videoScale;
pdf.line(x, y, x 15, y 15); // 15 instead of 30 for second x,y coordinates
}
}
pdf.dispose();
pdf.endDraw();
println("Printed pdf.");
}
if (key == 's') {
saveFrame("/Users/me/Desktop/img.png"); // change this
println("Image saved.");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/396949.html
上一篇:Capacitor3和Ionic6Android版本命中“uses-sdk:minSdkVersion1不能小于庫[:capacitor-app]中宣告的版本21”
