[Lib] ImageMessage (v2.1)- Send images to players via the chat!

Discussion in 'Resources' started by bobacadodl, Dec 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    bobacadodl

    ImageMessage updated! (v2.0)
    • Now using codename_B 's improved Color->ChatColor algorithm
    • Changed the way you create imagemessages. Instead of many static methods, created an ImageMessage builder class.
    • Added animated ImageMessages! Read from GIFs or an array of ImageMessages

    PS, do something like this to do animations!
    Code:
            final Player p = event.getPlayer();
            try {
                ImageInputStream imageInputStream = ImageIO.createImageInputStream(this.getResource("animation.gif"));
                final AnimatedMessage message = new AnimatedMessage(imageInputStream,8,ImageChar.BLOCK.getChar());
                new BukkitRunnable(){
                    @Override
                    public void run() {
                        if(p!=null){
                            p.sendMessage(" "); 
                            p.sendMessage(" "); 
                            message.next().sendToPlayer(p);
                        }
                        else{
                            cancel();
                        }
                    }
                }.runTaskTimer(this,10L,10L);
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    Garris0n, Skyost and hawkfalcon like this.
  2. Offline

    codename_B

    Making the world a more beautiful place! Nice job.
     
  3. Offline

    ShearsSheep

    You should be bukkit dev 1 day. Used this. Worked! Thanks Mate!
     
  4. Offline

    DevRosemberg

    codename_B I know this is offtopic but can you please read your pm? i need your help.

    Also: Awesome Lib Bob, keep up the good work :)
     
  5. Offline

    xCyanide

    bobacadodl
    I tried to make animated messages using your class, but there was an error. The error was input not set. I modified the AnimatedMessages class and it ended up working. This is the modified class.

    Code:java
    1. import javax.imageio.ImageIO;
    2. import javax.imageio.ImageReader;
    3. import javax.imageio.stream.ImageInputStream;
    4. import java.awt.image.BufferedImage;
    5. import java.io.File;
    6. import java.io.IOException;
    7. import java.util.ArrayList;
    8. import java.util.List;
    9.  
    10. /**
    11. * User: bobacadodl
    12. * Date: 1/25/14
    13. * Time: 10:41 PM
    14. */
    15. public class AnimatedMessage {
    16. private ImageMessage[] images;
    17. private int index = 0;
    18.  
    19. public AnimatedMessage(ImageMessage... images) {
    20. this.images = images;
    21. }
    22.  
    23. public AnimatedMessage(File gifFile, int height, char imgChar) throws IOException {
    24. this(ImageIO.createImageInputStream(gifFile), height, imgChar);
    25. }
    26.  
    27. public AnimatedMessage(ImageInputStream imageInputStream, int height, char imgChar) throws IOException {
    28. List<BufferedImage> frames = getFrames(imageInputStream);
    29. images = new ImageMessage[frames.size()];
    30. for (int i = 0; i < frames.size(); i++) {
    31. images[i] = new ImageMessage(frames.get(i), height, imgChar);
    32. }
    33. }
    34.  
    35. public ArrayList<BufferedImage> getFrames(ImageInputStream imageInputStream) throws IOException {
    36. ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
    37. ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
    38. reader.setInput(imageInputStream, false);
    39. int numOfImages = reader.getNumImages(true);
    40. for (int i = 0; i < numOfImages; i++) {
    41. BufferedImage image = reader.read(i);
    42. frames.add(image);
    43. }
    44. return frames;
    45. }
    46.  
    47. public ImageMessage current() {
    48. return images[index];
    49. }
    50.  
    51. public ImageMessage next() {
    52. ++index;
    53. if (index >= images.length) {
    54. index = 0;
    55. return images[index];
    56. } else {
    57. return images[index];
    58. }
    59. }
    60.  
    61. public ImageMessage previous() {
    62. --index;
    63. if (index <= 0) {
    64. index = images.length - 1;
    65. return images[index];
    66. } else {
    67. return images[index];
    68. }
    69. }
    70.  
    71. public ImageMessage getIndex(int index) {
    72. return images[index];
    73. }
    74. }[/i]
     
  6. Offline

    MrPotatoMuncher

  7. Offline

    bobacadodl

    Learn about bufferedImages in java. You can either load one from an online image file, or from a file inside your plugin
     
  8. Offline

    Arrxzon

    This is super cool, I was wondering how hypixel had done this.
    Thanks
     
  9. Offline

    DevRosemberg

    bobacadodl Hey bobac, can you please add Alpha Values support? Me and Comphenix want to add it to the NametagSpawner Lib.
     
  10. Offline

    bobacadodl

  11. Offline

    Comphenix

    I found the problem - it's due to the fact that your using the ignore-alpha constructor of Color objects. Add "true", and you'll be able to get the alpha color.
     
    Garris0n and bobacadodl like this.
  12. Offline

    bobacadodl

    The library is now updated to support transparent values :) Thanks Comphenix, I was wondering why it wasn't keeping the transparent values after the resize.

    I'm also working on a fork of this which will be tied into the FancyMessage library. So, you can make clickable images, or append clickable text to the image

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    Comphenix likes this.
  13. Offline

    Captain Dory

    I saw this on reddit :3
     
    Skyost likes this.
  14. Offline

    xXSniperzzXx_SD

    bobacadodl It seems as though when i use a url to get a picture it turns out as black, gray, white, and pink.

    This is what using the notch's head turned out as

    http://snag.gy/yAGWk.jpg
     
  15. Offline

    bobacadodl

    Yeah, it will have trouble converting certain pictures, because there are not many usable chat colors in minecraft. For example, there is no peach color, so skin colors either turns out as gold, pink, red, or grey/black. There is no brown chatcolor either, so brown is usually converted to dark grey/black.
     
  16. bobacadodl Sorry for that noob question,
    Do I just copy that code into my plugin, or do I have to do something else?
     
  17. Offline

    bobacadodl

    Uhm, yeah. Copy the entire package com.bobacadodl.imagemessage into your plugin. Then you will be able to use the imagemessage class.
     
  18. bobacadodl
    yeah, I've never used packages before, so how do I copy a package into my plugin

    Edit: ok, I figured it out,
    But I get errors with these imports:
    Code:java
    1. import com.sun.imageio.plugins.gif.GIFImageReader;
    2. import com.sun.imageio.plugins.gif.GIFImageReaderSpi;

    Code:
    Access restriction: The type GIFImageReader is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre7\lib\rt.jar
     
  19. Offline

    bobacadodl

    bluegru
    Hm, yeah some people have been reporting that their computers dont have those libraries. Just try deleting the AnimatedMessage class for now, if you dont need it.
     
  20. Offline

    Ultimate_n00b

    Swap your GIF frame reader code with this:

    Code:java
    1. public static List<BufferedImage> toPNG(File input) {
    2. List<BufferedImage> images = new ArrayList<BufferedImage>();
    3. try {
    4. ImageReader reader = ImageIO.getImageReadersBySuffix("GIF").next();
    5. ImageInputStream in = ImageIO.createImageInputStream(input);
    6. reader.setInput(in);
    7. for (int i = 0, count = reader.getNumImages(true); i < count; i++) {
    8. BufferedImage image = reader.read(i); // read next frame from gif
    9. images.add(image);
    10. }
    11. } catch (IOException ex) {
    12. ex.printStackTrace();
    13. }
    14. return images;
    15. }
     
    bobacadodl likes this.
  21. Offline

    Halginzz

    Could you add more information about the adding image into the lore? The code for lore, what you posted on the first page, doesn't work for me.
     
  22. Offline

    DevRosemberg

    bobacadodl Hey bob, i need your help with something private, mind if we talk it thorugh skype? If you dont mind please pm me your skype or just add me (DevRosemberg).
     
  23. Offline

    lordbobby104

    bobacadodl This is a very nooby question but I can't seem to figure out how to add a picture to my plugin. If anybody can help me that would be great!
     
  24. Offline

    bobacadodl

    lordbobby104
    What do you mean?
    Just take a look at the constructor for ImageMessage


    public ImageMessage(BufferedImage image,int height,char imgChar){

    As you can see, it takes in a BufferedImage, which is an image object, the height you want the image to be resized to, and the character to make the image out of.
     
  25. Offline

    lordbobby104

    bobacadodl Not what I ment, I was asking how you upload an image to the resource so that I can use the .getResource() method.
     
  26. Offline

    bobacadodl

    lordbobby104
    Just drag the .png file into your plugin folder
     
  27. Offline

    lordbobby104

  28. Offline

    pixelcraft12345

    hey are you able to point me in the right direction in adding this into a plugin thanks :)
     
  29. Offline

    akabarblake



    Sir, That is genius. Your players' will Love it!

    Codename, so I did not get the whole video, a little fast :)
    So it is just a more efficient way of finding the colors of RGB?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  30. Offline

    codename_B

    *better* not necessarily more efficient
     
Thread Status:
Not open for further replies.

Share This Page