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();

Similar Messages

  • 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();
    }

  • Help! BMP file info

    one BMP file has following binary formatting(in hexadecimal):
    42 4D 66 12 00 00 00 00 00 00 3E 00 00 00 28 00
    00 00 C5 00 00 00 A6 00 00 00 01 00 01 00 00 00
    00 00 28 12 00 00 12 17 00 00 12 17 00 00 00 00
    Since "66 12 00 00" is stored info about size of BMP file as well as other binary info. So I write
    getBMPInfo(File f), then use method skip() to find the related binary location. But I am sure how to get
    byte array include "66 12 00 00" in order to encoding. Can anyone tell me what to write next step, or give me an example?thx a lot.
    My code is following:
    import java.io.*;
    public class BMPInfo {
         public static void main(String[] args) throws IOException{
              File bmp= new File("E:\\logo1.bmp");
              getBMPInfo(bmp);
         public static void getBMPInfo(File f) throws IOException {
              FileInputStream fis= new FileInputStream(f);
                   fis.skip(16);//skip 16 bytes
                  fis.close();
    }

    I already posted an answer at your cross posting: http://forum.java.sun.com/thread.jsp?forum=31&thread=549453&tstart=0&trange=30

  • Having problem saving an iamge into a BMP file, please help!

    I'm writing a class to read an BMP image and output it again into another BMP file.
    After searching on the forum i have found some code for reading and writing bmp files, i put them togather to make up this class, however, the output bmp file is not correct, can anyone look at my code and tell me wots wrong? thanks!
    public class BMP {
    byte bf[]=new byte[14];
    //     private byte bitmapFileHeader [] = new byte [14];
    byte bi[]=new byte[40];
         public Image BMPReader(String filePath){
              Image image = null;
         try{
         FileInputStream fs=new FileInputStream(filePath);
         fs.read(bf,0,14); //Reads the 14byte fileheader      
         fs.read(bi,0,40); //reads the 40byte infoheader
         int nwidth=(((int)bi[7]&0xff)<<24) //pic width
         | (((int)bi[6]&0xff)<<16)
         | (((int)bi[5]&0xff)<<8)
         | (int)bi[4]&0xff;
         int nheight=(((int)bi[11]&0xff)<<24) //pic height
         | (((int)bi[10]&0xff)<<16)
         | (((int)bi[9]&0xff)<<8)
         | (int)bi[8]&0xff;
         int nbitcount=(((int)bi[15]&0xff)<<8) | (int)bi[14]&0xff;
         //pic size
         int nsizeimage=(((int)bi[23]&0xff)<<24)
         | (((int)bi[22]&0xff)<<16)
         | (((int)bi[21]&0xff)<<8)
         | (int)bi[20]&0xff;
         //parse 24bit bmp
         if(nbitcount==24){
         int npad=(nsizeimage/nheight)-nwidth*3;
         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;
         Toolkit kit=Toolkit.getDefaultToolkit();
         image=kit.createImage(new MemoryImageSource(nwidth,nheight,
         ndata,0,nwidth));
         else
              JOptionPane.showMessageDialog(null, "The choosen BMP image is not 24bit" +
                        "only 24bit bitmap is supported for BMP image.",
                   "Invalid image", 0);
              image=(Image)null;
         fs.close();
         }catch (Exception e){
         System.out.println(e);
         return image;
    //     --- 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 = 0;
         private int biHeight = 0;
         private int biPlanes = 1;
         private int biBitCount = 24;
         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 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 ();
         System.out.println("finished");
         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);
         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));
         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);
    }

    You dont have to write a whole program to read and write BMP files, rather I would recommend you to use latest version of JAVA.
    Java version 5 supports reading and writing of BMP images :)
    File file = new File("walkleft.bmp");
    BufferedImage bi = ImageIO.read(file);   // Here u can read bmp images
    ImageIO.write(BufferedImage, "bmp", new File("newimage.bmp"); //Same way you can write themCheers

  • Save a panel with a graphic into a bmp file

    I need to save a panel with a draw to a bmp file or a jpeg file, but I don't know which classes and methods I have to use.
    Thank for your help.

    Sorry, made an incomplete posting!!
    Here's all the code, hope it helps!
      public Image getScreenshot()
           double scale = 0.67;
              BufferedImage result = new BufferedImage( this.getWidth(), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR );
              Graphics2D g = (Graphics2D)result.getGraphics();
    //          g.scale( scale, scale );
              paintAll( g );
              // Crop image
           result = result.getSubimage( m_borderThickness,
                                                                                  m_borderThickness,
                                                                                  m_width-m_borderThickness,
                                                                                  m_height-m_borderThickness
           // Save as JPG
              String fname = "D:\\temp\\test4.jpg";
              try{
                   FileOutputStream out = new FileOutputStream( fname );
                   JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam( result );
                   param.setQuality( 1, false ); // use maximum quality
                   JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out );
                   encoder.encode( result );
                   out.close();
              } catch( IOException e ) {
                        e.printStackTrace();
                        throw new Error( "Could not save " + fname + " with JPEGImageEncoder" );
              // Load and Re-Scale JPG
              Image img = new ImageIcon( fname ).getImage();
              return result.getScaledInstance( (int)(result.getWidth() * scale),
                                                                                            (int)(result.getHeight() * scale),
                                                                                             //Image.SCALE_DEFAULT
                                                                                            Image.SCALE_AREA_AVERAGING
                                                                                            //Image.SCALE_SMOOTH
      }

  • 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);
    }

  • Save an 16 bits grayscale image in a bmp file

    Hello,
    I need to save a bmp file using an I16 grayscale picture.
    I already did the following VI that saves the picture in bmp but the colors are not good : there is only blue levels.
    I think there is a problem with the type of data that feed "array to color image" or with the colorscale but i don't manage to find where.
    Hope you can help me.
    Tank you.
    Ben 

    Hi
    The arraytocolorimage expects U32 because expects a RGB color, try this instead of the "toU32"
    Rodrigo Cuenca
    www.cidesi.com

  • Error while uploading *.BMP file using SE78

    Hi
    I am trying to upload a BMAP file from presentation server onto the document server using SE78.
    I am facing an error saying
    "This is not a *.BMP file(they begin with <> "BM")"
    Message no. TD874
    I have the necessary company logo in this file and I want to put this in the sapscript.
    Is there some formatting that needs to be done to the bitmap file before importing in SE78.
    Please help!
    Thanks
    Bala

    hi
    Convert BMP from <b>Command prompt using ren command</b>
    then follow below process
    Go to transaction SE78.
    Follow the path given below (on the left windows box) :-
    SAPSCRIPT GRAPHICS --> STORED ON DOCUMENT SERVER --> GRAPHICS --> BMAP
    Enter the name of the graphics file on the right side and Go to the menu GRAPHIC --> IMPORT
    The program is RSTXLDMC, the logo needs to be save in .TIF format.
    Use transaction SE78 to inmport graphics to SAP.
    In the form painter, you can either include directly to the form using menu Edit->Graphic->Create or using the INCLUDE statement in a window.
    To use an INCLUDE stanment, goto into the woindow script editor and use menu Include->Graphic. The include can look like this for a bitmap:
    /: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON
    regards
    vinod

  • Hp6500A plus. When I scan a document to PDF it is produced as a BMP file.

    My scan settings are correct and have been saving correctly. All of a sudden the scanner starts producing a BMP file instead of a PDF file.  It doesnt matter what i do it will not work correctly.  I have switched off eveything , retstarted , checked for updates and it does not seem to correct.  Any help out there ?

    Hi @avjohn, 
    I see that you are experiencing issues saving PDF files, they are saving as a BMP file instead. I would like to help.
    Run all the Windows Updates and Adobe Updates.
    Download and run the Print and Scan Doctor. It will diagnose the issue and might automatically resolve it.
    Find and fix common printer problems using HP diagnostic tools for Windows?
    Try scanning again.
    If the issue persists, uninstall and reinstall the printer software.
    Uninstalling the Printer Software.
    HP Officejet 6500A Plus e-All-in-One Printer - E710n Drivers.
    Select your operating system, click next and click on the software to download and install.
    Try and scan again.
    Update the printer's firmware if you are still havinging issues. HP Officejet 6500A Plus e-All-in-One Printer - E710n Drivers. Select your operating system, click next, click the link for firmware.
    What were the results when you ran the Print and Scan Doctor? (did it print or scan, any error messages)
    What operating system are you using? How to Find the Windows Edition and Version on Your Computer.
    What application are you scanning with?
    How is the printer connected? (USB/Ethernet/Wireless)
    Please provide in detail the results if you are still having issues.
    Have a nice weekend!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • 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

  • 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 save 4 bit .bmp file in photoshop

    I saved gif file to 4 bit bmp file, but the next time I try doing it I cannot, the photo shop does not support it. If I have to do I have to do it I have to close photoshop and open the application once again to save another gif file to bmp. I need a quick solution because there are 1000's of icon that needs to be saved to 4 bit bmp files. I need help please... Thanks

    No, it is not possible.
    PNG doesn't support layers.
    A few apps stuff their own private data into PNG to hide layer data, but well, it's private undocumented data.

  • How to modify KM upload to accept jpg/bmp files only?

    Hi All,
    I want to modify the KM upload command so that it accepts only ".jpg or ".bmp" file types. If any other file type is used then give an error message such as "Files of type jpg, bmp can only be uploaded". Also restrict the size to 1 or 2 MB only..
    I have also checked out some threads posted in this forum in this regard...
    I got 'UIUploadCommand.java' which is the class file of 'upload' (KM UICommand).
    but, i am not gettign the reference getContentType of the resource so that i can have a condition to upload only jpg/bmp files ...
    Awaiting your replies...
    Plz help..
    Regards,
    SK.

    Hi Srinath,
      i just ended up doing the same..
    Thanks for your reply...
    I have a problem ...
    I created a UI command called sk_upload with my class name...
    i have created a UI command group called sk_group
    i have added it in my Layoutset >> coll. renderer >> commands gruop >> sk_group.
    but, i don't see the command as a menu !
    Can u help me ?

  • Creating pie chart diagram in java  and converting into BMP file

    hi all ,
    my req. is to create draw a pie chart diagram and store
    the picture in BMP. it is Possible. if so how ?
    cheers
    senthil

    Hi Senthil,
    This response is a bit late but I hope it can help in some way.  Your requirement (to create draw a pie chart diagram and store the picture in BMP) is possible and actually quite easy if you don't mind using two open source libraries.  In his previous response to this thread, Detlev mentioned JFreeChart for as a solution for charting however he also mentioned that it lacks support for BMP.  Although this is true, you can use the JFreeChart library (http://www.jfree.org/jfreechart/index.html) in conjunction with an imaging library to meet your requirement.  I have used JFreeChart on multiple projects and I highly recommend it.  For the imaging library you have many options, however the only one I have used is The Java Imaging Utilities (JIU - http://jiu.sourceforge.net/).  Using these two class libraries, you can generate your pie chart and save it to a BMP file with the following block of code:
         try
             JFreeChart chart = this.createChart();
             FileOutputStream streamOut = new FileOutputStream("your/files/path/BMPfile.bmp");
             BufferedImage image = chart.createBufferedImage(600, 300);
             if(image == null)
                  reportError("Chart Image is NULL!!!!!!!!");
                  return(false);
             RGB24Image rgbImage = ImageCreator.convertImageToRGB24Image(image);
             Codec codec = new BMPCodec();
             codec.setImage(rgbImage);
             codec.setOutputStream(streamOut);
             codec.process();
             codec.close();
             streamOut.flush();
             streamOut.close();
        }catch(IOException ioExcept)
             // throw or handle IOException...
             return(false);
        }catch(OperationFailedException opFailedExcept)
             // throw or handle OperationFailedException...
             return(false);
    The first line inside the catch block calls a helper method that should create the actual chart using the JFreeChart library.  Once you have your chart instance (all chart types are represented using the JFreeChart class), you can then retrieve a BufferedImage of the chart (JFreeChart.createBufferedImage(int width, int height);).  In our situation, the BufferedImage class will act as an "intermediate" class, for both libraries (the charting and imaging) can make sense of BufferedImages.  The rest of the code deals with storing the generated chart (the BufferedImage) as a BMP file to disk.  The RGB24Image, Codec, BMPCodec, CodecMode, and OperationFailedException classes are all part of the JIU library.  Also, note that the storage  source is not solely limited to a File on disk; the Codec.setOutputStream(OutputStream os) method will accept any subclass of OutputStream.  This implies that not only can you store to the actual App Server disk (where your app is running) but also to sources such as Knowledge Management (KM) resources or even directly to the clients browser (in the case of an iView). 
    Once again, sorry for the late response and let me know if you have any questions regarding the code above. 
    Regards,
    Michael Portner

  • 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

Maybe you are looking for

  • Site Studio Designer Install on windows 7 - 64 bit

    has anyone installed designer on a 64 bit system? windows 7? thanks!

  • Purchase process report

    Hai Guru's i have a problem like today i recived one indent for Stores then convert this into PR on Today date, then  send to 3 vendors for RFQ, with in two day i got all the vendor quatation details, then created the compairtative statement, finally

  • Pre ordering iphone with other lines upgrade

    How would I go about pre ordering the iPhone 4s using another lines upgrade on my plan? Would I be forced to activate in store when the phone arrives? Basically what I mean, is if I pre-order at Apple.com (there is a form you fill out which takes you

  • ACR3 RAw processing vs. LIghtroom.

    Does anyone know if the raw processing engine to be released with LIghtroom is the same as ACR's current engine? I sure hope not because all versions of ACR have had issues with rendering the Red's with a slight orange tonality to them. The results I

  • Is CS5 a good edit program to edit mpeg-4 AVC/H.264 with?

    I always used adobe premiere pro 2 to edit DV. But now i've bought a new HD camera so i'm searching for a good program to edit my movies with. Right now I have to convert my HD movies in elements 7 and transfer it to adobe, but the result is very poo