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("उजगर",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);
}
Similar Messages
-
Convert a jpeg file into a 1-bit bmp file (2 colors image).
Hi. I�m having serious problems to convert a jpeg file into a 1-bit bmp file (2 colors image).
First, i,ve tried to get a 1-bit jpeg. But i think this is not possible, so what i have to do is to get a 1-bit bpm file.
I�m using FileSaver.saveAsBmp(String destination) and what i get is a bmp image, but with 16M colors, but what i want is a 2 colors bmp file. A black and white image.
Does anybody know how to do this? I�m really getting crazy with ths problem.
Thanks in advanceYou better read this at
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=733738 -
How to convert 864 Transaction code into XML in EDI to File Scenario
Hello Friends,
Can any body help me out in using 864 Transaction Code (Tex Message) in EDI to Flat File Conversion?? I mean i am using just 2 Fields i.e Name and Address.I didnt understand the Format given<u><i>..Here is the format for Name
N1 Name </i></u> Pos: 040 Max: 1
Heading - Optional
Loop: N1 Elements: 4
To identify a party by type of organization, name, and code
Element Summary:
<u><i>Ref Id Element Name Req Type Min/Max Usage</i></u>
N101 98 Entity Identifier Code M ID 2/3 Must use
Description: Code identifying an organizational entity, a physical
location, property or an individual
All valid standard codes are used.
N102 93 Name C AN 1/60 Used
Description: Free-form name
N103 66 Identification Code Qualifier C ID 1/2 Used
Description: Code designating the system/method of code structure used
for Identification Code (67)
All valid standard codes are used.
N104 67 Identification Code C AN 2/80 Used
Description: Code identifying a party or other code
Syntax:
1. N102 R0203 -- At least one of N102 or N103 is required.
2. N103 P0304 -- If either N103 or N104 are present, then the others are required.
Comments:
1. This segment, used alone, provides the most efficient method of providing organizational identification. To obtain this efficiency the "ID Code" (N104)
must provide a key to the table maintained by the transaction processing party.
2. N105 and N106 further define the type of entity in N101.
[<u>b]
Here is the format for Address</b></u>
N3 Address Information Pos: 060 Max: 2
Heading - Optional
Loop: N1 Elements: 2
To specify the location of the named party
Element Summary:
<b><u><i>Ref Id Element Name Req Type Min/Max Usage</i></u></b>
N301 166 Address Information M AN 1/55 Must use
Description: Address information
N302 166 Address Information
Description: Address information O AN 1/55 Used
So Help me hoe to convert this into XML...try this
For EDI U need SEEBURGER Adapter or Conversion agent by itemfield.
Using Conversion agent convert EDI Into XSD and Import using External definition.
Have look
EDI Conversion
Re: Seeburger Splitter adapter!!
Thanks -
How to convert a PDF file into a full editable WORD file?
Hi,
I tried to convert a pdf file into word but it is not fully editable. I can edit the title from the main page and that's it. The rest of the word document is saved as image. I tried editing teh pdf file but that one is not working either.
Please help on how to convert a PDF file into a full editable WORD file.
Thank youNot all PDF files are created equal. When a PDF file is created with Adobe Tools it is usually "tagged" with information about the fonts the images, the layout etc... This way when the PDF is saved to a new format like PPT or DOC then the results are usually usable. However, if you have a PDF file that was not tagged for some reason then run the Accessibility tools on the PDF to acquire some basic tagging. This may get you a better result. Also if you have a PDF that is an image, then you may want to run OCR on it.
-
How to convert a webpage program into a pdf file?
how to convert a webpage program into a pdf file?
Hi Federico,
ExportPDF is the program to convert PDF into different Formats(Doc, Docx, xlsx, rtf) and not Vice Versa, I would suggest you to use CreatePDF Web application for converting any other format to PDF.
For more details on CreatePDF
https://www.acrobat.com/createpdf/en/home.html
FAQ to be found here:
http://forums.adobe.com/community/createpdf?view=documents
~Pranav -
How do I convert a prel file into a mpeg or avi file?
how do I convert a prel file into a mpeg or avi file?
The Elements Tutorial Links Page http://forums.adobe.com/thread/1275830 will help... click the publish/share links
-
How to convert a .flv file into a Youtube sharing .mov file via Compressor?
I'm trying to convert a .flv file into a Youtube sharing .mov file via Compressor but every time I submit it, it fails due to error code -50. It worked two hours ago (albeit, very slowly) with another .flv file but now it refuses to even try. Please help!
Sorry you're having problems, but it's not surprising. The error code is invalid media.
The easy way is to forget about Compressor and upload the Flash file directly to You Tube with their uploader.
You'll also save a generation of compression loss.
Good luck.
Russ -
How to convert an NWDI project into a Local project?
Hi Experts,
Please tell me " how to convert an NWDI project into a Local project? "
If you cHi Srini
1. Copy/Paste Webdynpro components in the new project as was suggested before
2. Or create new project, copy _comp folder from old project to the new one. But, do not forget to update .dcdef & .project files manually after this. You have to set the correct project name in .dcdef and set the correct local project path in .project.
BR, Sergei -
How to convert my MM alias into an AppleID to use it with iCloud?
I used MobileMe and created a mail that became my Apple ID. Then I created an alias that became my main e-mail so now with iCloud I wish that aslias could become my Apple ID. I don't care to loose the first Apple ID but "How to convert my MM alias into an AppleID to use it with iCloud?"
You cannot convert an alias to Apple ID.
You can transfer your MM to iCloud with your main Apple ID.
There will be your alias as well.
Regards -
How to upload a Flat file into sap database if the file is in Appl'n Server
Hello Sap Experts , Can you tel me
" How to upload a Flat file into sap database if the file is in Application Server.
what is Path for that ?
Plz Tel Me its Urgent
Thanks for allHi,
ABAP code for uploading a TAB delimited file into an internal table. See code below for structures.
*& Report ZUPLOADTAB *
*& Example of Uploading tab delimited file *
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
DATA: ld_file LIKE rlgrap-filename.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 like pa0002-VORNA,
name2 like pa0002-name2,
age type i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Text version of data table
TYPES: begin of t_uploadtxt,
name1(10) type c,
name2(15) type c,
age(5) type c,
end of t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) type c.
constants: con_tab TYPE x VALUE '09'.
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
*START-OF-SELECTION
START-OF-SELECTION.
ld_file = p_infile.
OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
ELSE.
DO.
CLEAR: wa_string, wa_uploadtxt.
READ DATASET ld_file INTO wa_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
APPEND wa_upload TO it_record.
ENDIF.
ENDDO.
CLOSE DATASET ld_file.
ENDIF.
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
* Display report data for illustration purposes
loop at it_record into wa_record.
write:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
endloop. -
How to convert an int variable into String type
hi everybody
i want to know how to convert an interger variable into string variable
i have to implement a code which goes like this
Chioce ch;
for(int i=0;i<32;i++)
// here i need a code to convert the int variable i into a string variable
ch.add(String variable);
how do i convert that int variable i into a String type variable??
can anyone help me?Different methods:
int a;
string s=a+"";or
String.valueOf(int) is the better option because Int.toString() generated an intermediate object to get the endresult
Ema -
How to Convert Oracle Apps Report into XML Publisher
Hi
How to Convert Oracle Apps Report into XML Publisher?
ThanksIn Brief :
Re: XML Publisher
In Details :
http://www.oracle.com/technology/products/xml-publisher/docs/XMLEBSRep.pdf -
How to convert data from rows into columns
Hi,
I have a sql table and the data looks like this
GLYEAR GLMN01 GLMN02 GLMN03 GLMN04
2007 -109712.40 6909.15 4758.72 56.88
2007 -13411.32 19132.9 -5585.07 4362.64
Where GLyear reprsents Year and GLMN01 is February, GLMN02 is March and so on,
Now i want my output to be something like this which i want to insert into another table
GLYear GLMonth GLAmount
2007 February -109712.40
2007 March 6909.15
2007 April 56.88
My new table has 3 columns, GLYear,GLMonth,GLAmount.
Can someone please help me with the select statement on how to do this, i can work with the inserts.
Thanks.I want you to check these form tread they have the same discussion as you. They will definitely solve your problem
http://blog.jontav.com/post/8344518585/convert-rows-to-columns-columns-to-rows-in-sql-server
http://dba.stackexchange.com/questions/19057/convert-rows-to-columns-using-pivot-in-sql-server-when-columns-are-string-data
http://stackoverflow.com/questions/18612326/how-to-convert-multiple-row-data-into-column-data-in-sql-server
I hope this helps you in solving your problem.
Please remember to click “Mark as Answer” on the post that has answered your question as it is very relevant to other community members dealing with same problem in seeking the right answer -
Hi...
2.....how to convert normal function module into remote enabled function module?
thanks and regards,
k.swaminath.Hi,
In the attributes tab select radio button as remote enabled instead of normal..
u can call the remote enabled fm as...
CALL FUNCTION <Function module> destination <destination name>
Regards,
Nagaraj -
How to sent importet RAW files into the cloud? The files was importet from Canon EOS via camera adapter to the iPad. The Files was stored in the folder importet. But the files does not sync with photostream.
Welcome to the Apple community.
Only photos taken on the iOS device and after photo stream was enabled will be added to photo stream.
Maybe you are looking for
-
Problem in pricing conditions are not updated in BAPI_SAG_CHANGE
Hallo Friends, we have faced the one problem with the standard bapi *BAPI_SAG_CHANGE. we have passed the 10 item level data to the BAPI_SAG_CHANGE , the bapi BAPI_SAG_CHANGE successfully updated the 10 item level data to the schedule agreement . the
-
I want to create a simple web service using SOAP. I've googled around, but tutorials are either too simple (only primitives passed to web service, no user-defined instance) or incomplete. If possible, I wish to use Java built-in libs only, so no axis
-
Is tech care live a legitimate company?
My friend was told by an on-line apple support person that he should contact tech care live for help in fixing a hacked computer. Is this a legitimate company?
-
Transfer customized keyboard shortcuts to second Mac?
I have set up many custom keyboard shortcuts (both system-wide and for specific applications) in the Keyboard Settings panel. Instead of defining them all again, I would like to transfer these to a second Mac that I just purchased. I assume this woul
-
Starting Websphere Admin Server
Hi I'm trying to start the IBM WS AdminServer . This is one of the services of WebSphere. It fails to start with an error code 10. Has anyone any ideas Thanks S