سؤال

أرغب في التقاط صورة بالأبيض والأسود باستخدام J2Me أنا بخير مع التقاط الصور الملونة ولكنك أريد التقاط Iamge بالأبيض والأسود والرمادي

أين أقوم بتعيين هذه الخاصية في قماش الكاميرا ؟؟

هل كانت مفيدة؟

المحلول 2

باستخدام الكود التالي ، يمكنك تحويل الصورة إلى مقياس رمادي

import java.io.IOException;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;

public class Grey extends MIDlet {
    private Form frm;

public void startApp() {
    if (frm == null) {
        frm = new Form("Grey");
        try {
            Image img = makeGreyScale(Image.createImage("/test.png"));
            frm.append(img);
        } catch (IOException e) {
            frm.append(e.toString());
        }
        Display.getDisplay(this).setCurrent(frm);
    }
}

public void pauseApp() {
    // do nothing
}

public void destroyApp(boolean b) {
    // do nothing
}

// here is where the action is...
private static Image makeGreyScale(Image img) {
    // work out how many pixels, and create array
    int width = img.getWidth();
    int height = img.getHeight();
    int[] pixels = new int[width * height];
    // get the pixel data
    img.getRGB(pixels, 0, width, 0, 0, width, height);
    // convert to grey scale
    for (int i = 0; i < pixels.length; i++) {
        // get one pixel
        int argb = pixels[i];
        // separate colour components
        int alpha = (argb >> 24) & 0xff;
        int red   = (argb >> 16) & 0xff;
        int green = (argb >>  8) & 0xff;
        int blue  =  argb        & 0xff;
        // construct grey value
        int grey = (((red * 30) / 100) + ((green * 59) / 100) + ((blue * 11) / 100)) & 0xff;
        // reconstruct pixel with grey value - keep original alpha
        argb = (alpha << 24) | (grey << 16) | (grey << 8) | grey;
        // put back in the pixel array
        pixels[i] = argb;
    }
    // create and return a new Image
    return Image.createRGBImage(pixels, width, height, true);
}

}

نصائح أخرى

على الأرجح ستحتاج إلى اللعب مع إعدادات تشفير الصور للمديرhttp://java.sun.com/javame/reference/apis/jsr135/javax/microedition/media/manager.html#media_encodings

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top