How to Double BMP file

it is needed to create a new BMP file exactly twice the height of an original BMP file(which is uncompressed), and consisting of two copies of the original image, one on top of the other .
now I have modify the file size (ie. size of the bit map data+file size); doule the vaule of height, bit map data size, and calculate where the bit map data section stats(ie.the bit map data offset info)
But now I am not sure hwo to duplicate the entirebit map data section, then how to useFileout putStream and write() method to create a new double BMP file
Can anyone give me an example? Many thx.
My code is following:
import java.io.*;
public class BMPDouble {
     public static void main(String[] args) throws IOException{
          File bmp= new File(args[0]);
          getBMPInfo(bmp);
     public static void getBMPInfo(File f) throws IOException {
          FileInputStream fis= new FileInputStream(f);
               int bflen=14;  // 14 byte BITMAPFILEHEADER
              byte bf[]=new byte[bflen];
              fis.read(bf,0,bflen);
              int bilen=40; // 40-byte BITMAPINFOHEADER
              byte bi[]=new byte[bilen];
              fis.read(bi,0,bilen);
              int nsize = (((int)bf[5]&0xff)<<24)
                              | (((int)bf[4]&0xff)<<16)
                              | (((int)bf[3]&0xff)<<8)
                              | (int)bf[2]&0xff;
              int nheight = (((int)bi[11]&0xff)<<24)
                              | (((int)bi[10]&0xff)<<16)
                              | (((int)bi[9]&0xff)<<8)
                              | (int)bi[8]&0xff;
               int bmdsize = (((int)bi[23]&0xff)<<24)
                              | (((int)bi[22]&0xff)<<16)
                              | (((int)bi[21]&0xff)<<8)
                              | (int)bi[20]&0xff;
               int offsetInfo = (((int)bf[13]&0xff)<<24)
                              | (((int)bf[12]&0xff)<<16)
                              | (((int)bf[11]&0xff)<<8)
                              | (int)bf[10]&0xff;
               int newSize = nsize+bmdsize;
               int newHeight = nheight*2;
               int newBmdSize = bmdsize*2;
               System.out.println("Size: "+newSize+" bytes");
               System.out.println("Height: "+newHeight);
               System.out.println("Bit Map Data Size: "+newBmdSize);
               System.out.println("Bit Map Data offset: "+offsetInfo);
               fis.close();

thank you for code above, since it has some errors, so I change a little.
but I am not sure why in incomeData arrary should be 256. ie.byte[ ] incomeData = new byte[256];
whether it is also 14 bytes in new bit map file header and the rest is (256-14) bytes in new bit map info header? Please help me,thx.
My code is now following:
import java.io.*;
public class BMPDouble {
     public static void main(String[] args) throws IOException{
          File bmp= new File(args[0]);
          File bmpDouble= new File(args[1]);
          getBMPInfo(bmp);
          getBMPInfo(bmpDouble);
     public static void getBMPInfo(File f) throws IOException {
          FileInputStream fis= new FileInputStream(f);
          FileOutputStream fos= new FileOutputStream(f);
               int bflen=14;  // 14-byte BITMAPFILEHEADER
              byte bf[]=new byte[bflen];
              fis.read(bf,0,bflen);
              int bilen=40; // 40-byte BITMAPINFOHEADER
              byte bi[]=new byte[bilen];
              fis.read(bi,0,bilen);
              int nsize = (((int)bf[5]&0xff)<<24)
                              | (((int)bf[4]&0xff)<<16)
                              | (((int)bf[3]&0xff)<<8)
                              | (int)bf[2]&0xff;
              int nheight = (((int)bi[11]&0xff)<<24)
                              | (((int)bi[10]&0xff)<<16)
                              | (((int)bi[9]&0xff)<<8)
                              | (int)bi[8]&0xff;
               int bmdsize = (((int)bi[23]&0xff)<<24)
                              | (((int)bi[22]&0xff)<<16)
                              | (((int)bi[21]&0xff)<<8)
                              | (int)bi[20]&0xff;
               int offsetInfo = (((int)bf[13]&0xff)<<24)
                              | (((int)bf[12]&0xff)<<16)
                              | (((int)bf[11]&0xff)<<8)
                              | (int)bf[10]&0xff;
               int newSize = nsize+bmdsize;
               int newHeight = nheight*2;
               int newBmdSize = bmdsize*2;
               System.out.println("Size: "+newSize+" bytes");
               System.out.println("Height: "+newHeight);
               System.out.println("Bit Map Data Size: "+newBmdSize);
               System.out.println("Bit Map Data offset: "+offsetInfo);
               byte[] incomeData = new byte[256];
               int bytesRead;
               fos.write(NEWBITMAPFILEHEADER,0,NEWBITMAPFILEHEADER.length);
               fos.write(NEWBITMAPINFOHEADER,0,NEWBITMAPINFOHEADER.length);
               while((bytesRead=fis.read(incomeData))!= -1){
                    fos.write(incomeData,0,incomeData.length);
               fis.reset();
               while((bytesRead=fis.read(incomeData)) != -1){    
                    fos.write(incomeData,0,incomeData.length);
               fos.flush();
               fos.close();
               fis.close();
}

Similar Messages

  • Help! Double BMP file

    it is needed to create a new BMP file exactly twice the height of an original BMP file(which is uncompressed), and consisting of two copies of the original image, one on top of the other .
    now I have modify the file size (ie. size of the bit map data+file size); doule the vaule of height, bit map data size, and calculate where the bit map data section stats(ie.the bit map data offset info)
    But now I am not sure hwo to duplicate the entirebit map data section, then how to useFileout putStream and write() method to create a new double BMP file
    Can anyone give me an example? Many thx.
    My code is following:
    import java.io.*;
    public class BMPDouble {
         public static void main(String[] args) throws IOException{
              File bmp= new File(args[0]);
              getBMPInfo(bmp);
         public static void getBMPInfo(File f) throws IOException {
              FileInputStream fis= new FileInputStream(f);
                   int bflen=14;  // 14 byte BITMAPFILEHEADER
                  byte bf[]=new byte[bflen];
                  fis.read(bf,0,bflen);
                  int bilen=40; // 40-byte BITMAPINFOHEADER
                  byte bi[]=new byte[bilen];
                  fis.read(bi,0,bilen);
                  int nsize = (((int)bf[5]&0xff)<<24)
                                  | (((int)bf[4]&0xff)<<16)
                                  | (((int)bf[3]&0xff)<<8)
                                  | (int)bf[2]&0xff;
                  int nheight = (((int)bi[11]&0xff)<<24)
                                  | (((int)bi[10]&0xff)<<16)
                                  | (((int)bi[9]&0xff)<<8)
                                  | (int)bi[8]&0xff;
                   int bmdsize = (((int)bi[23]&0xff)<<24)
                                  | (((int)bi[22]&0xff)<<16)
                                  | (((int)bi[21]&0xff)<<8)
                                  | (int)bi[20]&0xff;
                   int offsetInfo = (((int)bf[13]&0xff)<<24)
                                  | (((int)bf[12]&0xff)<<16)
                                  | (((int)bf[11]&0xff)<<8)
                                  | (int)bf[10]&0xff;
                   int newSize = nsize+bmdsize;
                   int newHeight = nheight*2;
                   int newBmdSize = bmdsize*2;
                   System.out.println("Size: "+newSize+" bytes");
                   System.out.println("Height: "+newHeight);
                   System.out.println("Bit Map Data Size: "+newBmdSize);
                   System.out.println("Bit Map Data offset: "+offsetInfo);
                   fis.close();

    now,the code is all right.
    but it is strange that the print output such as newSize, newHeight,new Bit Map Data Size and Bit Map Data offset equals 0.
    Also, it exists IOException: disk has no enough space.
    Why it will happen?
    import java.io.*;
    public class BMPDouble {
         public static void main(String[] args) throws IOException{
              File bmp= new File(args[0]);
              File bmpDouble= new File(args[1]);
              getBMPInfo(bmp);
              getBMPInfo(bmpDouble);
         public static void getBMPInfo(File f) throws IOException {
              FileInputStream fis= new FileInputStream(f);
              FileOutputStream fos= new FileOutputStream(f);
                   int bflen=14;  // 14-byte BITMAPFILEHEADER
                  byte bf[]=new byte[bflen];
                  fis.read(bf,0,bflen);
                  int bilen=40; // 40-byte BITMAPINFOHEADER
                  byte bi[]=new byte[bilen];
                  fis.read(bi,0,bilen);
                  fis.mark((bflen+bilen)-1);
                  int nsize = (((int)bf[5]&0xff)<<24)
                                  | (((int)bf[4]&0xff)<<16)
                                  | (((int)bf[3]&0xff)<<8)
                                  | (int)bf[2]&0xff;
                  int nheight = (((int)bi[11]&0xff)<<24)
                                  | (((int)bi[10]&0xff)<<16)
                                  | (((int)bi[9]&0xff)<<8)
                                  | (int)bi[8]&0xff;
                   int bmdsize = (((int)bi[23]&0xff)<<24)
                                  | (((int)bi[22]&0xff)<<16)
                                  | (((int)bi[21]&0xff)<<8)
                                  | (int)bi[20]&0xff;
                   int offsetInfo = (((int)bf[13]&0xff)<<24)
                                  | (((int)bf[12]&0xff)<<16)
                                  | (((int)bf[11]&0xff)<<8)
                                  | (int)bf[10]&0xff;
                   int newSize = nsize+bmdsize;
                   int newHeight = nheight*2;
                   int newBmdSize = bmdsize*2;
                   System.out.println("Size: "+newSize+" bytes");
                   System.out.println("Height: "+newHeight);
                   System.out.println("Bit Map Data Size: "+newBmdSize);
                   System.out.println("Bit Map Data offset: "+offsetInfo);
                   byte[] NEWBITMAPFILEHEADER = new byte[bflen];
                   byte[] NEWBITMAPINFOHEADER = new byte[bilen];
                   byte[] incomeData = new byte[256];
                   int bytesRead;
                   fos.write(NEWBITMAPFILEHEADER,0,NEWBITMAPFILEHEADER.length);
                   fos.write(NEWBITMAPINFOHEADER,0,NEWBITMAPINFOHEADER.length);
                   while((bytesRead=fis.read(incomeData))!= -1){
                        fos.write(incomeData,0,incomeData.length);
                   fis.reset();
                   while((bytesRead=fis.read(incomeData)) != -1){    
                        fos.write(incomeData,0,incomeData.length);
                   fos.flush();
                   fos.close();
                   fis.close();

  • 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 can I OPEN files I just downloaded? They're on the DOWNLOADS screen of Firefox but I can't open them even after double-clicking? And they're not on the FOLDERS as well. I tried RIGHT-CLICK and the "open dowloading folder" or something does not work! P

    How can I OPEN files I just downloaded? They're on the DOWNLOADS screen of Firefox but I can't open them even after double-clicking? And they're not on the FOLDERS as well. Even the right-click is not working ... the "open containing folder" does not work.
    == This happened ==
    Not sure how often
    == ALWAYS! ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.5; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)

    Open Containing Folders is never active.

  • How to call GOS(Generic Object service) attachment ( BMP file ) into SAP

    How to call GOS(Generic Object service) attachment ( BMP file ) into SAP script
    Example: MM02 Service object there attaching the bmp file the same file i need to call script based on the material number
    Please provide the procedure and  coding.
    Thanks in advance
    Raju

    Hi,
    The following link may be useful to u.
    help.sap.com/printdocu/.../BCSRVOBS.pdf

  • Load .bmp file into BLOB column in 9i - how to?

    Hello all,
    How do I update a table with a BLOB column with a .bmp file in 9i? I tried using the DBMS_LOB package but got a ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275 (and since there is more native support in 9i, I'm not sure I need it to begin with). We do not have Inter-Media. tia [email protected]

    Hi,
    please, search a bit on the forum before do a question:
    Just searching by "upload blob pdf" ...
    How to batch upload PDF files into database BLOB
    Regards,
    Jose.

  • How do I read in a .bmp file?

    How do I read in a .bmp file to a program that uses
    an ASCII file? Is it possible to change the file to ASCII
    prior to reading the file into the program?
    Thanks for all your help!

    MIME?

  • 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]

  • 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

  • How to batch convert bmp files into jpg by dos command or c# program language?

    How to batch convert bmp files into jpg by dos command or c# program language?
    Many thanks for replying.

    Try
    GraphicsMagick.

  • How to open a file by double clicking in an RUNNING exe built by LabVIEW

    I am developing an applicationg using LabVIEW. But found some difficulties.
    This is an editor, and I link this app to a certain file format.
    So I hope when I double click this file, My exe will load it. This could be done by read application command line.
    But if my exe is runing already, I double click the file, I could not get the latest command line information.
    When the exe is running, How doule click the file to send some sort of info the this exe so the exe could open a new one.
    How to do this in LabIVEW?
    Solved!
    Go to Solution.

    Hi,
    You have to make the Vi reentrant so that it does not share the same memory location:
    Regards,
    Even
    Certified LabVIEW Associate Developer
    Automated Test Developer
    Topro AS
    Norway

  • How can create color table for "write bmp file.vi"?

    i want to create a color table for a 8 bit bitmap.The color table is the input of "write bmp file.vi". how can i make it?
    thanks!

    > i want to create a color table for a 8 bit bitmap.The color table is
    > the input of "write bmp file.vi". how can i make it?
    > thanks!
    >
    There is a color control on the front panel numerics palette. A color
    in LV is a four byte xRGB formatted number. So you can make an array of
    the color numerics and set them by hand or format the numbers however
    you like. If unwired it will use the LV color palette which is pretty
    much the HTML palette.
    Greg McKaskle

  • How to converting a flash clip into a bmp file quickly

    Hi,
    I’d like to get help on converting a flash clip into a
    bmp file. I have an application developed with ActiveX technology.
    There is a flash control embedded in the ActiveX control, which has
    a printing button. The end users can press the printing button to
    print the flash picture as well as other text content.
    I get the flash picture for printing in follow steps:
    1.Create a BitmapData object
    var bmp:BitmapData = new BitmapData(w, h, false);
    2.Obtain the image of current flash
    bmp.draw(mc, mc.transform.matrix, new ColorTransform(), 1,
    new Rectangle(x, y, w, h));
    3.Get pixels of flash image one by one in loop, and save them
    into a PixelCollection
    bmp.getPixel(col, row);
    4.Move the PixelCollection into flash container
    fscommand("print", load_PixelCollection);
    5.Ocx control gets the PixelCollection and converts it into
    BMP format
    But I find it is very slow when action script gets pixels one
    by one. Getting pixels of a middle size flash may spend one minute.
    It is hard for our customer to stand. Does anyone have idea to get
    the flash image quickly? 
    Any help is appreciated.
    Shi Hang

    What about the built-in print methods, wouldn't it be better
    to use those here?
    Getting all pixel values is a time intensive process, because
    of the amount of pixels. It may be a bit faster if you split the
    getPixel() loop over some frames, but I'm not exactly sure how to
    do that (just read it somewhere).
    If the content is fixed, you could create the pixel array in
    the background while the user looks at it. This is quite some
    overhead, but when the user decides to print, the array would
    already be there.
    Finally, not helpful here, but interesting:
    quote:
    BitmapData.getPixels()
    No longer do you have to loop through every pixel in a
    bitmap, one at a time with getPixel to send a bitmap to the server.
    This method returns a ByteArray containing the hexadecimal color
    value of each of the pixels in the specified rectangular region of
    a bitmap. Use this method in conjunction with the new ZLib
    compression method; ByteArray.compress() to compress and send a
    bitmap over the wire to a server so it can be converted into a file
    ready for downloading.
    (from
    http://www.flashguru.co.uk/actionscript-3-new-capabilities/)
    This will be available in AS 3.
    hth,
    blemmo

  • How to save a CWGraph into a bitmap (.bmp) file in Visual C++?

    I plot (chart) data into a graph control on a MFC dialog in Visual C++ and I need to save the image into a bmp file. I found the ControlImage method, but did not find any way to use it in Visual C++.
    I would also like to retrieve the chart data (the point charted on the graph for each plot) and to use them to build data files. How to do it?

    Dealing with images in VC++ is far from easy. You would need to create the following objects: CBitmap, CArchive, CPictureHolder and a CDC.
    Then call the SelectObject function on the CDC and pass in the CBitmap object. Then you can put the image of the graph in the CPictureHolder with:
    ph.SetPictureDispatch((LPPICTUREDISP)m_CWGraph.Con​trolImage().m_lpDispatch);
    where ph is the CPictureHolder and m_CWGraph is the CWGraph.
    Then you can render the image to the bitmap CDC by calling the CPictureHolder::Render function. It will ask for the bounds of the picture in CRect form as well.
    Then you can call the CBitmap.Serialize function with the CArchive object which should be pointing to the appropriate BMP file. Don't you just love MFC?
    As for you second qu
    estion, you can't retrieve the data that has been plotted to the graph. We don't maintain the data that is sent in because it would be very inefficient memory usage since data is usually decimated for display. I would recommend that you just send your data to a global buffer at the same time as plotting.
    Best Regards,
    Chris Matthews
    Measurement Studio Support Manager

  • How to find a BMP file included with Applicatio​n in LabView?

    I have a VI that I would like to build into an application (.EXE).  The VI has a Picture indicator, whose source is a BMP on my local hard drive.  Using "Read BMP File.vi" and a Path constant, it's relatively easy to read the BMP and display it in the indicator.  I know how to include the file with the distribution (Build App or DLL -> Installer Settings -> Files), but how does one determine the location of the file after users install the EXE? I tried using just the filename of the picture in the path constant, hoping it would look in it's current directory, but I received an error.  With the full path in the path constant, everything works just fine.
    Thank you,
    ...jerry

    You can reconstruct the path. Use the "Current VI's path" to get the
    path of the caller VI. Then use the "Build path" and Strip path" to
    build the path to your file.
    Note that in an executable, the VIs path includes the executable, like
    the following:  C:\directory_name\my_exec.exe\main.vi
    The attached code (image) should do it (or at least give you a start).
    Regards;
    Enrique
    www.vartortech.com
    Attachments:
    path_to_file.gif ‏2 KB

Maybe you are looking for