亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

文本形狀的圖像裁剪

文本形狀的圖像裁剪

慕少森 2019-07-05 15:26:35
文本形狀的圖像裁剪我需要在另一個圖像中剪出一個文本形狀的圖像。我認為最好用圖片來展示。文本圖像將始終是黑色的透明背景,并由此產生的剪除也應該有一個透明的背景。兩個輸入圖像也將是相同的大小。
查看完整描述

3 回答

?
浮云間

TA貢獻1829條經驗 獲得超4個贊

創建一個新的BufferedImage并對Word cat的所有像素進行迭代,如果它們是黑色的,則將cat圖像像素復制到新圖像中。

以下是一些代碼:最后的工作代碼,支持反別名。)

public static BufferedImage textEffect(BufferedImage image, BufferedImage text) {
    if (image.getWidth() != text.getWidth() ||
        image.getHeight() != text.getHeight())
    {
        throw new IllegalArgumentException("Dimensions are not the same!");
    }
    BufferedImage img = new BufferedImage(image.getWidth(),
                                          image.getHeight(),
                                          BufferedImage.TYPE_INT_ARGB_PRE);

    for (int y = 0; y < image.getHeight(); ++y) {
        for (int x = 0; x < image.getWidth(); ++x) {
           int textPixel = text.getRGB(x, y);
           int textAlpha = (textPixel & 0xFF000000);
           int sourceRGB = image.getRGB(x, y);
           int newAlpha = (int) (((textAlpha >> 24) * (sourceRGB >> 24)) / 255d);
           int imgPixel = (newAlpha << 24) |  (sourceRGB & 0x00FFFFFF);
           int rgb = imgPixel | textAlpha;
           img.setRGB(x, y, rgb);

        }
    }
    return img;}


查看完整回答
反對 回復 2019-07-05
?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

使用GlyphVector..使用Font班級,等級

public GlyphVector layoutGlyphVector(FontRenderContext frc,
                                         char[] text,
                                         int start,
                                         int limit,
                                         int flags) {

你可以得到輪廓Shape從字形矢量到公共抽象形狀getOutline()

分配大綱Shape作為你的剪貼畫Graphics舉個例子。

在圖形上繪制圖像。

只有剪裁過的形狀才會被填充。


查看完整回答
反對 回復 2019-07-05
  • 3 回答
  • 0 關注
  • 400 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號