Convert a jpeg file into a 1-bit bmp file (2 colors image).

Hi. I�m having serious problems to convert a jpeg file into a 1-bit bmp file (2 colors image).
First, i,ve tried to get a 1-bit jpeg. But i think this is not possible, so what i have to do is to get a 1-bit bpm file.
I�m using FileSaver.saveAsBmp(String destination) and what i get is a bmp image, but with 16M colors, but what i want is a 2 colors bmp file. A black and white image.
Does anybody know how to do this? I�m really getting crazy with ths problem.
Thanks in advance

You better read this at
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=733738

Similar Messages

  • How to convert a jpeg file into a 1-bit bmp file (2 colors image)

    Hi. I�m having serious problems to convert a jpeg file into a 1-bit bmp file (2 colors image).
    I�m using FileSaver.saveAsBmp(String t) but what i get is a bmp image, but with 16M colors, but what i want is a 2 colors bmp file. A black and white image.
    Does anybody know how to do this? I�m really getting crazy with ths problem.
    Thanks in advance

    Hi opalo,
    this code may help you...
    import java.awt.*;
    import java.io.*;
    import java.awt.image.*;
    import javax.imageio.ImageIO;
    class Write1 extends Component {
    //--- Private constants
    private final static int BITMAPFILEHEADER_SIZE = 14;
    private final static int BITMAPINFOHEADER_SIZE = 40;
    //--- Private variable declaration
    //--- Bitmap file header
    private byte bitmapFileHeader [] = new byte [14];
    private byte bfType [] = {'B', 'M'};
    private int bfSize = 0;
    private int bfReserved1 = 0;
    private int bfReserved2 = 0;
    private int bfOffBits = BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
    //--- Bitmap info header
    private byte bitmapInfoHeader [] = new byte [40];
    private int biSize = BITMAPINFOHEADER_SIZE;
    private int biWidth = 50;
    private int biHeight = 70;
    private int biPlanes = 1;
    //private int biBitCount = 24;
    private int biBitCount = 1;
    private int biCompression = 0;
    private int biSizeImage = 0x030000;
    private int biXPelsPerMeter = 0x0;
    private int biYPelsPerMeter = 0x0;
    private int biClrUsed = 0;
    private int biClrImportant = 0;
    //--- Bitmap raw data
    private int bitmap [];
    //--- File section
    private FileOutputStream fo;
    //--- Default constructor
    public Write1() {
    public void saveBitmap (String parFilename, Image parImage, int
    parWidth, int parHeight) {
    try {
    fo = new FileOutputStream (parFilename);
    save (parImage, parWidth, parHeight);
    fo.close ();
    catch (Exception saveEx) {
    saveEx.printStackTrace ();
    * The saveMethod is the main method of the process. This method
    * will call the convertImage method to convert the memory image to
    * a byte array; method writeBitmapFileHeader creates and writes
    * the bitmap file header; writeBitmapInfoHeader creates the
    * information header; and writeBitmap writes the image.
    private void save (Image parImage, int parWidth, int parHeight) {
    try {
    convertImage (parImage, parWidth, parHeight);
    writeBitmapFileHeader ();
    writeBitmapInfoHeader ();
    writeBitmap ();
    catch (Exception saveEx) {
    saveEx.printStackTrace ();
    * convertImage converts the memory image to the bitmap format (BRG).
    * It also computes some information for the bitmap info header.
    private boolean convertImage (Image parImage, int parWidth, int parHeight) {
    int pad;
    bitmap = new int [parWidth * parHeight];
    PixelGrabber pg = new PixelGrabber (parImage, 0, 0, parWidth, parHeight,
    bitmap, 0, parWidth);
    try {
    pg.grabPixels ();
    catch (InterruptedException e) {
    e.printStackTrace ();
    return (false);
    pad = (4 - ((parWidth * 3) % 4)) * parHeight;
    biSizeImage = ((parWidth * parHeight) * 3) + pad;
    bfSize = biSizeImage + BITMAPFILEHEADER_SIZE +
    BITMAPINFOHEADER_SIZE;
    biWidth = parWidth;
    biHeight = parHeight;
    return (true);
    * writeBitmap converts the image returned from the pixel grabber to
    * the format required. Remember: scan lines are inverted in
    * a bitmap file!
    * Each scan line must be padded to an even 4-byte boundary.
    private void writeBitmap () {
    int size;
    int value;
    int j;
    int i;
    int rowCount;
    int rowIndex;
    int lastRowIndex;
    int pad;
    int padCount;
    byte rgb [] = new byte [3];
    size = (biWidth * biHeight) - 1;
    pad = 4 - ((biWidth * 3) % 4);
    if (pad == 4) // <==== Bug correction
    pad = 0; // <==== Bug correction
    rowCount = 1;
    padCount = 0;
    rowIndex = size - biWidth;
    lastRowIndex = rowIndex;
    try {
    for (j = 0; j < size; j++) {
    value = bitmap [rowIndex];
    rgb [0] = (byte) (value & 0xFF);
    rgb [1] = (byte) ((value >> 8) & 0xFF);
    rgb [2] = (byte) ((value >> 16) & 0xFF);
    fo.write (rgb);
    if (rowCount == biWidth) {
    padCount += pad;
    for (i = 1; i <= pad; i++) {
    fo.write (0x00);
    int b = 1200;
    fo.write(b);
    rowCount = 1;
    rowIndex = lastRowIndex - biWidth;
    lastRowIndex = rowIndex;
    else
    rowCount++;
    rowIndex++;
    //--- Update the size of the file
    bfSize += padCount - pad;
    biSizeImage += padCount - pad;
    catch (Exception wb) {
    wb.printStackTrace ();
    * writeBitmapFileHeader writes the bitmap file header to the file.
    private void writeBitmapFileHeader () {
    try {
    fo.write (bfType);
    fo.write (intToDWord (bfSize));
    fo.write (intToWord (bfReserved1));
    fo.write (intToWord (bfReserved2));
    fo.write (intToDWord (bfOffBits));
    catch (Exception wbfh) {
    wbfh.printStackTrace ();
    * writeBitmapInfoHeader writes the bitmap information header
    * to the file.
    private void writeBitmapInfoHeader () {
    try {
    fo.write (intToDWord (biSize));
    fo.write (intToDWord (biWidth));
    fo.write (intToDWord (biHeight));
    fo.write (intToWord (biPlanes));
    fo.write (intToWord (biBitCount));
    fo.write (intToDWord (biCompression));
    fo.write (intToDWord (biSizeImage));
    fo.write (intToDWord (biXPelsPerMeter));
    fo.write (intToDWord (biYPelsPerMeter));
    fo.write (intToDWord (biClrUsed));
    fo.write (intToDWord (biClrImportant));
    // DataOutputStream temp = new DataOutputStream(fo);
    // int m = 32;
    // temp.writeInt(m);
    catch (Exception wbih) {
    wbih.printStackTrace ();
    * intToWord converts an int to a word, where the return
    * value is stored in a 2-byte array.
    private byte [] intToWord (int parValue) {
    byte retValue [] = new byte [2];
    retValue [0] = (byte) (parValue & 0x00FF);
    retValue [1] = (byte) ((parValue >> 8) & 0x00FF);
    return (retValue);
    * intToDWord converts an int to a double word, where the return
    * value is stored in a 4-byte array.
    private byte [] intToDWord (int parValue) {
    byte retValue [] = new byte [4];
    retValue [0] = (byte) (parValue & 0x00FF);
    retValue [1] = (byte) ((parValue >> 8) & 0x000000FF);
    retValue [2] = (byte) ((parValue >> 16) & 0x000000FF);
    retValue [3] = (byte) ((parValue >> 24) & 0x000000FF);
    return (retValue);
    class Writebmp
         public static void main(String args[])
              //Image img = Toolkit.getDefaultToolkit().getImage("jatin.bmp");
              try
              File filename = new File("jatin_test.bmp");
              BufferedImage image = ImageIO.read(filename);
              Graphics graphics = image.getGraphics();
              graphics.drawString("&#2313;&#2332;&#2327;&#2352;",10,30);
              Write1 w = new Write1();
              Image img = Toolkit.getDefaultToolkit().getImage("jatin_test.bmp");
              w.saveBitmap("jatin_test.bmp",img,200,200);
              catch (IOException e)
    System.err.println ("Unable to write to file");
    System.exit(-1);
    }

  • How do I convert a jpeg file into a pdf file?

    I would like to be able to convert a jpeg file, both in Photoshop and outside of Photoshop, into a pdf file.  How do I go about doing that?

    If you don't have Acrobat, you'll need to do it in Photoshop. File>Save as>Photoshop PDF. If it is a cmyk file, you'll need to convert it to rgb first.

  • How do you convert a jpeg file into word document so i can edit it?

    How do you convert a jpeg file into word document so i can edit it?

    http://office.microsoft.com/en-us/mac-word-help/training-edit-pictures-in-office -for-mac-2011-RZ103709558.aspx

  • How do I convert a Jpeg file to a PDF file

    How do I convert a jpeg file to a pdf file?

    Hi Rick
    With a paid subscription to Adobe CreatePDF you can covert a jpeg to PDF
    See https://www.acrobat.com/createpdf/en/home.html for further information and pricing plans

  • How do I convert PDF/JPEG file in "Brush Script MT" font to Word Document

    How do I convert PDF/JPEG file in "Brush Script MT" font to Word Document? (I checked with Acrobat XI pro but no use

    You cannot in Adobe Reader. You can try in Acrobat, but first you must try to run OCR (Text Recognition). I have never tried OCR on a script font.

  • Converting a .numbers file to an image?

    I have a spreadsheet that I will be updating every so often that I want to present to a group of people on a message board as an image. Is there a way to convert a .numbers file to an image, or can I convert to an image once I convert the .numbers to pdf or .xls?

    If you don't need the entire spreadsheet but only a portion, you can use screenshots. OSX comes prebuilt with some great shortcuts that give you multiple ways of getting them, far more flexible than M$. Look at this website that has the shortcuts listed and explained:
    http://guides.macrumors.com/TakingScreenshots_in_Mac_OSX
    Example: I almost never use Preview to convert because I can just use CMD & Shift & 4 to get a cross-hair and create a perfect tiff of the area I drag the cross-hairs around, right on the desktop.
    Jason

  • How do I convert a JPEG file to an Adobe Reader (PDF) file?

    Please help me. I have scanned an image of a text in a book.  The scanned image is automatically uploaded into a JPEG file.  How do I convert this into a PDF file?

    None of the free Adobe Reader products provide the capability of converting image files (e.g. jpeg, gif, png) to PDF.
    You can either use
    Acrobat XI Pro or Standard - Scan to PDF
    Adobe PDF Pack (formerly known as CreatePDF): online subscription service - JPEG to PDF Converter
    You may find some free non-Adobe apps or online services.  But the quality of PDF output may vary.
    Unless you use OCR (Optical Character Recognition), the scanned image of text will not be recognized as real text.  So you will not be able to highlight text, for example.

  • RAW files converted to JPEG files on my mac can't be seen by my customer who has a PC: WHY?

    I have been using Adobe CS5 for over a year now but only recently discovered how Adobe Bridge helps with work flow and post processing. My first time using Bridge I put all my RAW NEF files into folders and, after processing them in Photoshop, put all the JPEG files into a seperate folder. Before sending said JPEG images to my client, I batch renamed them to make sure the image file numbers were in the proper consecutive order. My client, who is a PC user, received these images and said she was unable to view them. Her computer system isn't outdated and I'm not sure what the issue is. I'm wondering if there was a formating change that happened when I did the batch rename or if the problem is Adobe Bridge altogether? I did all these on my Mac Book Pro which is only a year old..What am I missing??

    Did each image have its .jpg extension? i think Windows likes to see the extension, Macs don't care.

  • How do I convert an flv file to still images?

    This may sound stupid, but I have a downloaded flv file, and I want to use about
    8 seconds  to make still images so I can trace into Illustrator and then export it into Flash. (both are older versions).
    Is this possible?
    It is for an animinated logo.
    Thanx.

    Andrew J wrote:
    Everybody's wrong wrong wrong. You don't need garageband. Select the song, go to info. You need to select a start and stop time for the song that can't be any longer than 40 seconds in length. Then in advanced mode you convert the song to acc. once done locate the file on the computer. it should end in .m4a . Change the a to an r so it reads .m4r Drag the file to the desktop, double click and it ends up in ringtones folder.
    That's it! Works every time. Or for those who want easier:
    http://www.ambrosiasw.com/utilities/iToner/
    My drug of choice.

  • How to convert an html file to an image

    Any Sample Codes.........................

    I need the code in java for this conversion.If the scrolling is there in html......then by snap shot it will not come totally..............I need total html......converted to image..........

  • How to setup jpeg file as background image for all site pages and resolution stay same?

    I have uploaded my new site to http://wwwtjhtestdec2012.businesscatalyst.com
    I have background image set the same on all site pages  but image is incorrectly zoomed way in on some pages (like Home page for example).
    The Donate Page shows the correct resolution which I want displayed on all site pages.
    How do I set all other site pages to match background image resolution of the Donate Page?
    I am not sure what I am doing wrong that is changing this, or if it's possibly a bug?
    I want the background image to be full screen on all site pages please advise how to resolve.
    I would appreciate the assistance!
    Thank you kindly!
    Tammy

    I have re-uploaded my site to http://wwwtjhtestdec2012.businesscatalyst.com.
    If I set the Master page to Tile vertically that is only way I can get full screen background image of vegetables (without distortion).
    Then however another issue occurs....
    On Home Page of site I set same property to Tile and the background is better (no visible line where tiles meet---above the navigation tool bar--that is what I want for all pages associated to Master.
    So logically, I tried setting a 2nd associated site page to same master, to Tile but on Statement of Faith Page, notice the horizontal line where tiles meet, above my navigation bar on that site page?
    Why does Muse not handle both site pages associated to the same master identically?
    Any of the other options besides Tile or Tile vertically cause the background to not fill entire screen.
    Ideas?

  • Can I convert a jpeg into an eps file without illustrator?

    I do not have illustrator and I need to convert a jpeg file into an eps file. Is there a way to do this without illustrator?

    You can re-save the jpeg as EPS from Photoshop,
    but if you need a vector eps, you will need Illustrator or an equivalent program to do it. Also, depending upon the complexity of your file, it may not be able to be an automatic convertsion.

  • How can I convert a wave file to a jpeg file (picture) is it possible???

    Hello:
    How can I convert a wave file to a jpeg file (picture) is it possible???

    zuckini;
    I am pretty sure you know, but just to be completely sure: a wave is (usually) sound signal and a jpeg file is an image.
    If you mean how to display the wave signal in a graph and then save the graph as a jpeg file, then just drop a graph indicator in the control panel, wire the signal. Check any of the example shipped with LabVIEW on how to do this. To get the image, drop a graph indicator's invoke node in the block and select "Get Image". Check this page for detailed information.
    If you have something else in mind, please reply to this message with additional information about the wave signal, the image, etc.
    Regards;
    Enrique
    www.vartortech.com

  • How can i convert a jpeg doc to pdf on macbook

    how can i convert a jpeg doc into a pdf doc?

    Open it in Preview and choose Export from the File menu.
    (112944)

Maybe you are looking for

  • Playing iPod connected to 24/7 power

    Hey guys, I need help. My iPod mini displays "no battery power remains connect to power" or watever but the simple fact is that i actually have heaps of battery power. I found the iPod useless to me, and decided to get a new one. My dad paid for the

  • New computer.. can't get photoshop back

    About 2 weeks ago my computer burned up...  ended up getting an new one. Most important, just about a year and a half ago I paid bank for CS6 ...got the new computer running. I got onto my adobe account, downloaded CS6 == however my serial number won

  • Panic crashes on Intel iMac

    I'm getting more frequent "panic crashes" and think they're related to my use of Pages and Numbers, now that I've finally switched to Lion (a few  months ago).  I've had two in the last few days, after none for several weeks. The last two were precee

  • Screen remains blank after call/voicemail

    Like it should, my iPhone screen goes blank when I am speaking on the phone and when I am listening to a voicemail. However, about 75% of the time, my screen does not reappear after the phone call has been completed or after listening to a voicemail.

  • Livecycle hosted service provider

    It appears that livecycle policy server is out of reach (financially) for small design firms. Unless I'm missing something. Is it feasible to setup a multi-user hosted service provider? If a small firm needed to use the service they could subscribe t