2013-05-07 68 views
0

我是Qt中的新成員。我正在研究圖像的旋轉。在我的情況下,旋轉工作正常,但旋轉後出現黑色填充背景。我想刪除或隱藏黑色背景。如何在圖像旋轉後移除黑色填充背景

我正在使用MAC。所以我正在使用「Imageevent」applescript。我的腳本是這樣的:告訴應用程序「圖像事件」。

launch 
set this_image to open this_file 
rotate this_image to angle 270 
save this_image with icon 
close this_image 
end tell 

除了這個劇本我自己也嘗試這個Qt代碼爲圖像旋轉:

void MyWidget::rotateLabel() 
{ 
    QPixmap pixmap(*my_label->pixmap()); 
    QMatrix rm; 
    rm.rotate(90); 
    pixmap = pixmap.transformed(rm); 
    my_label->setPixmap(pixmap); 
} 
+0

你怎麼旋轉?發佈一些代碼 – UmNyobe 2013-05-07 11:20:19

+0

這不是Qt問題,而是applescript的問題。 – Trompa 2013-05-07 14:22:21

+0

你好Trompa,我已經嘗試了Qt代碼以及我編輯過的問題。請通過它告訴我,如果你對我有任何建議。\ – Ashish 2013-05-08 04:42:43

回答

1

幾口似乎保持透明背景的至少PNG文件:

sips -r 270 /tmp/a.png -o /tmp/b.png 

你可以也使用ImageMagick:

convert -rotate 270 /tmp/a.png /tmp/b.png 
2

您也可以墊圖像用指定的色彩......

set myFile to "/Users/JD/Desktop/test.png" 
do shell script "sips -r 270 " & quoted form of myFile & " --padColor FFFFFF -i" 

編輯 您可以在下面腳本另存爲一個應用程序,並在其上放文件...

on open of theFiles 
    repeat with aFile in theFiles 
     set filePath to quoted form of (aFile's POSIX path) 
     do shell script "sips -r 270 " & filePath & " --padColor FFFFFF -i" 
    end repeat 
end open 
+0

請告訴我如何使用它。我不知道這個腳本的用法,我會很感激。 thnks。 – Ashish 2013-05-08 04:45:25

+0

我已經包括編輯 – adayzdone 2013-05-08 04:50:30

+0

對不起adayzdone,它仍然不適合我。我正在做的是:我已經將這個腳本寫在文本文件上,然後將其保存爲.sh文件在終端上運行。我的方式是正確還是有問題?請告訴我 – Ashish 2013-05-08 05:29:17