2013-05-07 67 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