Display .bmp files

How can I display .bmp files with java?

Yes using JAI - using core methods or just the codec.
You only need the jars. A full install on the desktop or server is not required but the C libs a full install provides MIGHT make things a little faster.
Programming guide:
http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/JAITOC.fm.html
Have fun!

Similar Messages

  • How to open a bmp file

    I Want to display a bmp file and use an image icon to display it, how do I do this?
    tnx

    Hi
    I am giving you the source code to display BMP file in Java
    SOURCE CODE =======>>
    public Image loadBitmap (byte[] bmpImage)
    Image image = null;
    try
    ByteArrayInputStream fs=new ByteArrayInputStream(bmpImage);
    int bflen=14; // 14 byte BITMAPFILEHEADER
    byte bf[]=new byte[bflen];
    fs.read(bf,0,bflen);
    int bilen=40; // 40-byte BITMAPINFOHEADER
    byte bi[]=new byte[bilen];
    fs.read(bi,0,bilen);
    // Interpret data.
    int nsize = (((int)bf[5]&0xff)<<24) | (((int)bf[4]&0xff)<<16) | (((int)bf[3]&0xff)<<8)| (int)bf[2]&0xff;
    int nbisize = (((int)bi[3]&0xff)<<24)| (((int)bi[2]&0xff)<<16) | (((int)bi[1]&0xff)<<8)| (int)bi[0]&0xff;
    int nwidth = (((int)bi[7]&0xff) << 24) | (((int)bi[6]&0xff)<<16) | (((int)bi[5]&0xff)<<8)| (int)bi[4]&0xff;
    int nheight = (((int)bi[11]&0xff) << 24)| (((int)bi[10]&0xff)<<16)| (((int)bi[9]&0xff)<<8)| (int)bi[8]&0xff;
    int nplanes = (((int)bi[13]&0xff)<<8)|(int)bi[12]&0xff;
    int nbitcount = (((int)bi[15]&0xff)<<8)|(int)bi[14]&0xff;
    // Look for non-zero values to indicate compression
    int ncompression = (((int)bi[19])<<24)|
    (((int)bi[18])<<16)| (((int)bi[17])<<8)|(int)bi[16];
    int nsizeimage = (((int)bi[23]&0xff)<<24)|
    (((int)bi[22]&0xff)<<16)| (((int)bi[21]&0xff)<<8)|
    (int)bi[20]&0xff;
    int nxpm = (((int)bi[27]&0xff)<<24)|
    (((int)bi[26]&0xff)<<16)| (((int)bi[25]&0xff)<<8)|
    (int)bi[24]&0xff;
    int nypm = (((int)bi[31]&0xff)<<24)| (((int)bi[30]&0xff)<<16)| (((int)bi[29]&0xff)<<8)| (int)bi[28]&0xff;
    int nclrused = (((int)bi[35]&0xff)<<24)|(((int)bi[34]&0xff)<<16)| (((int)bi[33]&0xff)<<8)| (int)bi[32]&0xff;
    int nclrimp = (((int)bi[39]&0xff)<<24)| (((int)bi[38]&0xff)<<16)| (((int)bi[37]&0xff)<<8)| (int)bi[36]&0xff;
    Toolkit tk = Toolkit.getDefaultToolkit();
    if (nbitcount==24)
    * No Palette data for 24-bit format butscan lines are
    * padded out to even 4-byte boundaries.
    int npad = (nsizeimage / nheight) - nwidth * 3;
    if (npad == 4)
    npad = 0;
    int ndata[] = new int [nheight * nwidth];
    byte brgb[] = new byte [( nwidth + npad)* 3 * nheight];
    fs.read (brgb, 0, (nwidth + npad) * 3 *nheight);
    int nindex = 0;
    for (int j = 0; j < nheight; j++)
    for (int i = 0; i < nwidth; i++)
    ndata [nwidth * (nheight- j - 1) + i] = (255&0xff)<<24 | (((int)brgb[nindex+2]&0xff)<<16)|(((int)brgb[nindex+1]&0xff)<<8) | (int)brgb[nindex]&0xff;
    nindex += 3;
    nindex += npad;
    image = tk.createImage( new MemoryImageSource (nwidth, nheight, ndata, 0, nwidth));
    else if (nbitcount == 8)
    * Have to determine the number ofcolors, the clrsused
    * parameter is dominant if it is greaterthan zero. If
    * zero, calculate colors based onbitsperpixel.
    int nNumColors = 0;
    if (nclrused > 0)
    nNumColors = nclrused;
    else
    nNumColors = (1&0xff)<<nbitcount;
    // Some bitmaps do not have the sizeimagefield calculated// Ferret out these cases and fix 'em.
    if (nsizeimage == 0)
    nsizeimage =((((nwidth*nbitcount)+31) & ~31 ) >> 3);
    nsizeimage *= nheight;
    int tempSize = ((((nwidth*nbitcount)+31)& ~31 ) >> 3);
    tempSize *= nheight;
    // Read the palatte colors.
    int npalette[] = new int [nNumColors];
    byte bpalette[] = new byte[nNumColors*4];
    fs.read (bpalette, 0, nNumColors*4);
    int nindex8 = 0;
    for (int n = 0; n < nNumColors; n++)
    npalette[n] = (255&0xff)<<24|(((int)bpalette[nindex8+2]&0xff)<<16)|(((int)bpalette[nindex8+1]&0xff)<<8)|(int)bpalette[nindex8]&0xff;
    nindex8 += 4;
    * Read the image data (actually indices into the palette)//
    * Scan lines are still padded out to even 4-byte// boundaries.
    int npad8 = (nsizeimage / nheight) -nwidth;
    int ndata8[] = new int [nwidth*nheight];
    byte bdata[] = new byte[(nwidth+npad8)*nheight];
    fs.read (bdata, 0,(nwidth+npad8)*nheight);
    nindex8 = 0;
    for (int j8 = 0; j8 < nheight; j8++)
    for (int i8 = 0; i8 < nwidth;i8++)
    ndata8[nwidth*(nheight-j8-1)+i8] = npalette[((int)bdata[nindex8]&0xff)];
    nindex8++;
    nindex8 += npad8;
    image = tk.createImage( new MemoryImageSource (nwidth, nheight, ndata8, 0, nwidth));
    //support for 4Bpp bmps...
    else if (nbitcount == 4)
    int nNumColors = 0;
    if (nclrused > 0)
    nNumColors = nclrused;
    else
    nNumColors = (1&0xff)<<nbitcount;
    * Some bitmaps do not have the sizeimagefield calculated//
    * Ferret out these cases and fix 'em.
    if (nsizeimage == 0)
    nsizeimage =((((nwidth*nbitcount)+31) & ~31 ) >> 3);
    nsizeimage *= nheight;
    * Read the color table. BMP's always have the complete color
    * table when the number of colors used = 0
    int npalette[] = new int [nNumColors];
    byte bpalette[] = new byte[nNumColors*4];
    fs.read (bpalette, 0, nNumColors*4);
    int nindex8 = 0;
    for (int n = 0; n < nNumColors; n++)
    npalette[n] = (255&0xff)<<24|(((int)bpalette[nindex8+2]&0xff)<<16)|(((int)bpalette[nindex8+1]&0xff)<<8)|(int)bpalette[nindex8]&0xff;
    nindex8 += 4;
    * Read the image data (actually indicesinto the palette)//
    * Scan lines are still padded out toeven 4-byte// boundaries.
    int half = nwidth/2;
    if (nwidth%2 != 0)
    half++;
    int npad4 = (nsizeimage / nheight) -half;
    int tempSize = ((((nwidth*nbitcount)+31)& ~31 ) >> 3);
    tempSize *= nheight;
    int ndata4[] = new int [2*half*nheight];
    byte bdata[] = new byte [(half +npad4)*nheight];
    fs.read (bdata, 0, (half +npad4)*nheight);
    int nindex4 = 0;
    for (int j4 = 0; j4 < nheight; j4++)
    for (int i4 = 0; i4 < half; i4++)
    int i1 =nwidth*(nheight-j4-1)+(2*i4) ;
    ndata4 [i1] = npalette[((int)bdata[nindex4]&0xf0)>>4];
    ndata4 [i1+1] = npalette[((int)bdata[nindex4]&0xf)];
    nindex4++;
    nindex4 += npad4;
    image = tk.createImage( new MemoryImageSource (nwidth, nheight, ndata4, 0, nwidth));
    //support for monochrome...
    else if (nbitcount == 1)
    int nNumColors = 0;
    if (nclrused > 0)
    nNumColors = nclrused;
    else
    nNumColors = (1&0xff)<<nbitcount;
    * Some bitmaps do not have the sizeimagefield calculated
    * Ferret out these cases and fix 'em.
    if (nsizeimage == 0)
    nsizeimage =((((nwidth*nbitcount)+31) & ~31 ) >> 3);
    nsizeimage *= nheight;
    * Read the color table...
    * BMP's always have the complete color table when the number
    * of colors used = 0
    int npalette[] = new int [nNumColors];
    byte bpalette[] = new byte[nNumColors*4];
    fs.read (bpalette, 0, nNumColors*4);
    int nindex1 = 0;
    for (int n = 0; n < nNumColors; n++)
    npalette[n] = (255&0xff)<<24|(((int)bpalette[nindex1+2]&0xff)<<16)|(((int)bpalette[nindex1+1]&0xff)<<8)|(int)bpalette[nindex1]&0xff;
    nindex1 += 4;
    * Read the image data (actually indicesinto the palette)
    * Scan lines are still padded out to even 4-byte// boundaries.
    int limit = nwidth/8;
    int npad1 = (nsizeimage / nheight) -limit;
    if (nwidth%8 != 0)
    int tempSize = ((((nwidth*nbitcount)+31)& ~31 ) >> 3);
    tempSize *= nheight;
    int ndata1[] = new int[(nwidth*nheight)];
    byte bdata[] = new byte [(limit +npad1)*nheight];
    fs.read (bdata, 0, (limit +npad1)*nheight);
    nindex1 = 0;
    for (int j1 = 0; j1 < nheight; j1++)
    for (int i1 = 0; i1 < limit;i1++)
    int id1 =nwidth*(nheight-j1-1)+(8*i1);
    * here each bit of thearray should be converted to a
    * byte - 0 or 1
    ndata1 [id1] = npalette[(int)((bdata[nindex1]&0x80)>>7)];
    ndata1 [id1+1] = npalette[(int)((bdata[nindex1]&0x40)>>6)];
    ndata1 [id1+2] = npalette[(int)((bdata[nindex1]&0x20)>>5)];
    ndata1 [id1+3] = npalette[(int)((bdata[nindex1]&0x10)>>4)];
    ndata1 [id1+4] = npalette[(int)((bdata[nindex1]&0x8)>>3)];
    ndata1 [id1+5] = npalette[(int)((bdata[nindex1]&0x4)>>2)];
    ndata1 [id1+6] = npalette[(int)((bdata[nindex1]&0x2)>>1)];
    ndata1 [id1+7] =npalette [(int)(bdata[nindex1]&0x1)];
    nindex1++;
    nindex1 += npad1;
    image = tk.createImage( new MemoryImageSource (nwidth, nheight, ndata1, 0, nwidth));
    else
    image = (Image)null;
    fs.close();
    return image;
    catch (Exception e)
    e.printStackTrace();
    return (Image) null;
    Deepak
    [email protected]

  • Loading bitmap (.BMP) files

    I am writing a sort of Image Viewers with Flex 2 - loading
    and displaying image files resided in local disk.
    Using mx.controls.Image class, I could load and display the
    JPG / GIF / PNG files at runtime.
    But I could not do the BMP files with the Image class (or
    control); what I get is only broken-image icon.
    Still I don't understand why the BMP format files are not
    included in the "Bitmap object".
    How can I load / display BMP files in Flex 2 MXML
    application?
    Thanks in Advance,
    Joseph

    Hi,
    I have tried the loader.unload(); method and now I get this
    following error:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference.
    at loadCorrect_fla::MainTimeline/clip1()
    I am obviously missing the point here, but how am I doing
    this wrong?
    Kind Regards,
    Boxing Boom

  • Want to display a .bmp file in reports

    Hello there
    I am trying to display a .bmp file on reports which I think is simple.the main problem is that After making changes to report we transfer the report file to Unix and then generate the report in unix and print it and in that process the report stops printing.
    Thanks in advance.
    Jha

    make sure SOURCE FILENAME is valid in your LINK FILE pointing to the image.bmp
    Report compiles nicely even with wrong source filename, only when opening layout editor an error message will appear.

  • Tranferring Display Data on an Agilent DSO6014L to a .BMP file

    Hello,
    I'm able to read the DSO6014L Scope Display Data into a .bmp file, but I can't open it. Windows say the file must be corrupted, or to large. My file is the the same size as the .bmp file that's saved to my memory stick on the scope. There's something different, but I not sure what it could be. Any ideas. Thanks.
    Test Engineering
    Empower RF Systems Inc.
    Attachments:
    SCOPE Dump Plot 2 File.vi ‏20 KB

    Mal,
    It looks like you are using the Write to Binary File VI, don't you want to use Write to Bitmap?
    Ian K.
    Applications Engineer
    National Instruments

  • How to display a 16-bit bmp file

    Hi,
    i have a 16 bit BMP file available in a byte[] along with the BITMAPINFO information. how to display this in Java.
    i was able to find the code for displaying the 8-bit/24-bit BMP file in Javaworld :Java Tip 43 .
    Pls provide pointers to sample/example code if available.

    Try JAI it supports 8, 16, and 32 bit image data types.
    http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/index.html

  • Why java only can display GIF file not jpeg and BMP ??

    Did anyone know why java only can display GIF file not in jpeg and BMP ?? This is because the quality of GIS is not as good as Jpeg and BMP
    any code to load the display process ??
    thx guys !!!

    you can do jpegs but im not sure about bmps.
    The only thing ive noticed is that java cant support transparent jpegs, only transparent gifs
    Jim

  • Cfdocument - using cf7 - displaying .bmp & .tiff files

    I'm using CF7's cfdocument tag (with no hope of upgrading to
    CF8 anytime soon). I'm generating PDFs and not able to display .bmp
    or .tiff files in the PDF. This was a known issue in this version.
    -Has there been a fix, hotfix, or scheduled fix?
    -Is there a workaround?
    Thanks -

    You might take a look at iText. It is what cfdocument uses
    behind the scenes. It is not as simple as using cfdocument, but it
    should be possible.

  • .bmp files do not show as icons in the event library - I am having to convert them to .jpg  to achieve a display

    Although .bmp files are to some extent supported, I find that on importing them they do not show as icons in the event library. I am having to convernt them to .jpg files to produce this result.   Am I doing something wrongly, or is this the experience of others as well?

    Yes - I've posted one of the files to Dropbox and it appears perfectly in picture form on my IPad.   So it seems there is nothing wrong with the files.  I'm even more puzzled now!  I'll try to upload a smaller (less than 2mb) file here.  The files I am using in the project, which is a kind of family history using stills,  are a complete mix of types - tif, jpg, Canon raw(cr2), psd and bmp.   Some, including, I suspect, many of the .bmps are scans from old prints, as this one.

  • Preview doesn't display bmp image

    Using Bootcamp, I saved a BMP image file of a windows screenshot. I can view the screenshot with Tiger & Preview properly, but when I open the file with Leopard & Preview, the entire image is blank except for the windows image resize buttons in the top right corner.
    Using Leopard and Quicktime, I can view the image. Also I can display the image properly using Microsoft Word on Leopard. I cannot see the image when I insert it into Pages on Leopard.
    Why is the BMP file viewable with only certain applications? Does Preview, under Leopard, no longer support BMP files?

    I tried using the link you provided to report the problem to Apple, but it wouldn't log me in. Do you have to be a developer to use Bug Report? If so, perhaps a developer could confirm this as a problem, and report it.
    I posted the offending BMP file to my iDisk account: http://idisk.mac.com/rush1-Public
    Problem: On a Leopard system the BMP is not displayed properly using Preview or Pages, but it is viewable using QuickTime or MSWord.

  • Why the value of 24bit bmp file read by the labview different from the original

    when i use labview to read a bmp file,it looks just fine,but the the pixel value is dfferent from the original,how it changed,can i change it back

    right... Your "result" indicator is an I16, it goes from -32768 to 32767... so that's not enough, before the 2 for loops, just after the Integer to colour value VI  you should place a convertion node to convert to i64 and also change you result display representation to i64.
    See attached VI.
    Hope this helps
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    lll.vi ‏42 KB

  • Are GIF, BMP files not supported?

    Are GIF, BMP formats not supported? When I hit the import button, GIF and BMP files are not displayed.
    If I put a *.* into the File Name box, then those file types appear. If I select a BMP or GIF and attempt to import it, I get the message "no photos were found to import". I've searched the LR help files for terms GIF and BMP and found zero results. Anyone?

    Supported files are the RAW formats, JPEG, TIFF, and PSD with maximum compatibility on during save. If I forgot one, someone will probably correct me. I'm pretty sure gif, bmp and png are not supported.
    Which camera do you have that produces gifs and bmps?

  • Emailing .BMP Files

    'Some' .BMP files that are emailed to me simply show up as an icon at the end of the message with 'filename.bmp' posted below it.
    I thought that maybe it wasn't downloaded so I would refresh the email or click on it to try to get it to download but it doesn't change anything. I can't get it to display from the email. It doesn't seem to be a size issue.
    Going into the mail from my computer I can detach the picture and transfer it over to the iPhone through sync and view it without a problem. Any ideas on what we are doing wrong?

    You were right again.
    Seems this also helped answer my earlier incompatibility issue too. Looks like the iTunes software converts all pictures to .JPG when you load them onto your iPhone. Pictures that I have in my sync folder have been converted to .JPG when I select them to mail out to someone else. It's also quite picky about the exact format of the .JPG incoming from outside sources.
    When I use an external email source to email myself a .BMP it does not display the picture, just an icon with the filename displayed below it.

  • Open .BMP files

    Hi
    On SP 2013
    Having some BMP files ...now it opens up within IE  
    - how do I force it to open in Paint? 
     

    Issue
    When you inserted an image, it was displayed as a thumbnail instead of a full image.
    Solution
    If the image you insert is not associated with the MS Paint application, it will not display correctly
    To correct this issue, you will need to force a .bmp file extension association with MS Paint. Follow these steps:
    In Windows Explorer, find a .bmp file and select it.
    Right-click the .bmp file. Click Open With.
    In the Open With dialog box, select MS Paint if it is in the list. If not, click Browse and search for the MS Paint application. It should be located in theC:\Windows\system32 directory.
    Select the Always use this program to open the selected file check box.
    Click OK.
    Now the .bmp extension will be associated with MS Paint.
    If you are not able to associate the .bmp extension with MS Paint, you can override the setting in the registry:
    On the Start menu (Windows), click Run.
    In the Run dialog box, enter regedit.
    In the Registry Editor, locate the following key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.bmp
    Right-click the (Default) entry. Click Modify.
    In the Edit String dialog box, under Value data, enterPaint.Picture.
    Click OK.
    DushYant'

  • Why do JPEG files show up as BMP files when I email

    Can someone help me send a full size JPEG Picture to a windows user without it changing it to a BMP file? I have chosen 'Always send windows-friendly attachments' and chosen 'Full Size', but it comes across as a .BMP file instead of JPEG.
    Please help

    If the person is using Yahoo on the other end they have to view your attachments by clicking on the "search shortcuts" and "my attachments". Then they will see the attachments as jpgs and have an option to download them. I am not sure what is happening because jpegs that I send by editing them in Adobe Photoshop Elements and dragging into mail attach in Yahoo normally.
    Yahoo may be using bmp files to display the files when the actual file is actually a jpeg.
    Kurt

Maybe you are looking for

  • How can I remove my old phone?

    I recently got a new Iphone 4 and wonder how I can remove the profile for the 3Gs in Itunes? It still shows up in such things as Find my Iphone and such.

  • Powerbook G4 will not install OS X

    Hey guys, so my sister gave me her old Powerbook G4 15inch 1.5 ghz. She had a lot of stuff on it and I had the great idea of reinstalling the system software and starting fresh. I did the following: 1) Started up in Target Disk Mode 2) Plugged it int

  • Acrobat Pro 9.4 Problems

    I am having several problems with my Acrobat Pro. When I am adding pages to a document, (dragging and dropping from explorer) the pages pane is hiding pages where I can't get to them. If I have 11 pages, and the page pane set to see two pages at a ti

  • Can i use my iphone in ecuador?

    can i use my iphone in ecuador?

  • Pixel Dimensions and File Size

    Can anybody please explain the relation between pixel dimensions and file size? Being naive, (or straight-forward if you prefer) I had assumed that pixel dimensions wide times pix dimension high = file size. Wrong! For instance a .JPG file 374 X 500