On Tuesday, December 11, 2018 at 11:16:22 PM UTC-5, Shai Almog wrote:
>
> What's RenderedImage? That's an AWT class.
> Try:
>
> ImageIO.save(img, outputStream, ImageIO.FORMAT_JPEG, 0.9f);
>

Please disregard the  RenderedImage cast as this was copied from my Java 
Swing project

Getting "error: non-static method save(Image,OutputStream,String,float) 
cannot be referenced from a static context" 

I have attached a basic class MyApplication to demonstrate the error.

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/46bd645a-4375-4b90-bf4c-7cebbb4b0d04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
package com.mycompany.myapp;

import com.codename1.io.Log;
import static com.codename1.ui.CN.*;
import com.codename1.ui.Dialog;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.Toolbar;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import java.io.ByteArrayOutputStream;

/**
 * This file was generated by <a href="https://www.codenameone.com/";>Codename
 * One</a> for the purpose of building native mobile applications using Java.
 */
public class MyApplication {

    private Form current;
    private Resources theme;

    public void init(Object context) {
        // use two network threads instead of one
        updateNetworkThreadCount(2);

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);

        addNetworkErrorListener(err -> {
            // prevent the event from propagating
            err.consume();
            if (err.getError() != null) {
                Log.e(err.getError());
            }
            Log.sendLogAsync();
            Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
        });
    }

    public byte[] getBytesFromImage(com.codename1.ui.Image image) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        try {
            com.codename1.ui.util.ImageIO.save(image, outputStream, com.codename1.ui.util.ImageIO.FORMAT_JPEG, 9.0f);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return outputStream.toByteArray();
    }

    public void start() {
        if (current != null) {
            current.show();
            return;
        }
        Form hi = new Form("Hi World", BoxLayout.y());
        hi.add(new Label("Hi World"));
        hi.show();
    }

    public void stop() {
        current = getCurrentForm();
        if (current instanceof Dialog) {
            ((Dialog) current).dispose();
            current = getCurrentForm();
        }
    }

    public void destroy() {
    }

}

Reply via email to