开发者

Possible to compress an image and possibly change to different type?

I'm having a problem finding an answer for this...

What I want is a method that takes in a byte array for a given image and compresses it. If I've understood things correctly, png is a good way to compress an image if it has a lot of the same colors, so it would be nice to be able t开发者_运维百科o convert the mime-type to png as well during the process. That is, if the image is not allready png format.

This is what I have in mind:

public static byte[] compressImage(byte[] imagebytes) {

    //do the compression here

    return imagebytes;
}


You could do it through Java Image API but I discourage this because it's not so powerful neither so cool to use.

A better solution would be to interface to ImageMagick through JMagick. It will be somewhat more complex to get into but you will have a fully fledged flexible engine to work with images (under many formats)..

If you want to keep it the old way then start from the Oracle tutorial here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜