0

PNG を表す byteArray がありますが、これを webP に変換したいと考えています。次のコードがあります。コードで com.sksamuel.scrimage.Image を使用し、システム ライブラリ webp_jni をロードします。

val image = Image(content) //content of PNG of type Array[Byte]
extension match {
    case "webp" => Ok(
        libwebp.WebPEncodeRGB(
            image.write,
            image.width,
            image.height,
            image.width * 3,
            80F)
        ).as("image/webp")
    case _ => Ok(image.write).as("image/png")
}

png 画像をリクエストするとすべて正常に動作しますが、webP 画像をリクエストすると、次のようになります。

#  SIGSEGV (0xb) at pc=0x00007fc008287377, pid=14883, tid=140461610465024
#
# JRE version: Java(TM) SE Runtime Environment (8.0_05-b13) (build 1.8.0_05-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libwebp.so.5+0x33377]  WebPPictureAlloc+0x407

ストライド入力 image.width に他の値を試してみました。image.width は 4 の倍数に丸められ、image.width は 3 の倍数に丸められました。この場合、クラッシュしませんが、画像は非常にノイズが多く、オリジナル。

4

1 に答える 1

0

プロジェクトをwebp-imageioライブラリを使用するように切り替えたところ、次の方法で実装できました。

val image = Image(content) //content of PNG of type Array[Byte]
extension match {
    case "webp" => {
        val out = new ByteArrayOutputStream()
        ImageIO.write(resizedImage.awt, "webp", out)
        Ok(out.toByteArray).as("image/webp")
    case _ => Ok(image.write).as("image/png")
}
于 2014-06-04T14:14:42.120 に答える