Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
harshalsuri #1
Convert image into byte array
I am trying to insert an image in the word document using RTF specifiations.
The problem i am facing is that in RTF we have to provide a byte string for
the image
I have developed a program in VB that converts image into Byte string. Now
what i want to do is convert the image to byte string in coldfusion. I have
successfully incorporated logic in coldfusion, only problem is that i use
<cffile action="READBINARY" file="mypicture.bmp" variable="pic">
now i want to convert this binary data into byte array.
harshalsuri Guest
-
How to save a Byte array on to the desktop?
Hi All, I am taking Byte array once clicked and that is being printed in an swfloader in the same page. I want the same to be saved as a image... -
#38760 [NEW]: php_mssql fails to convert multi-byte UTF-8 to UCS-2
From: aireater at gmail dot com Operating system: Windows 2003 Server PHP version: 5.1.6 PHP Bug Type: MSSQL related Bug... -
error byte array
hi I think this code is ok but im getting this bytearray error - and mentions OLE Object <cfquery name="Recordset1" datasource="dependent">... -
Convert a Byte value to Numeric - Possible?
Among the usual suspects: 1. Asc requires (apparently) an ansi value as argument. I'm dealing with the HO bits in a byte. 2. Cint requires a... -
How to Convert a Byte to its Numeric Value?
I need access to the bits of a Byte expression, and the logical functions operatge bit-wise on numeric vales - per the VBScript CHM. So how do I... -
tkrussel #2
Re: Convert image into byte array
You should be able to do this using java. The standard java.io package is
useful for reading files. However, due to ColdFusion's data type conversions I
cannot think of a way to use those classes directly to get a byte array into an
Array object in CF.
So... Your best bet may be to write a short bit of java code to read the file
into a byte array and return that array. I've attached some sample code. You'll
need to save it as IOUtils.java and compile it, then place the resulting .class
file in CF's classpath (probably under your root folder, then WEB-INF/classes).
Once the code is compiled and in your classpath, you can use it in CF like
this:
<cfset fileBytes = CreateObject( "java", "IOUtils" ).readFully(
"mypicture.bmp" )>
/************************* Begin IOUtils.java ****************************/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class IOUtils {
private IOUtils() {
}
/**
* Read the file into a byte array and return it
*/
public static byte[ ] readFully( String filename ) throws IOException,
FileNotFoundException {
FileInputStream fileIn = null;
byte[ ] fileBytes = null;
try {
File file = new File( filename );
if( file.exists( ) ) {
fileBytes = new byte[ ( int ) file.length( ) ];
byte[ ] buff = new byte[ Math.min( fileBytes.length, 1024 ) ];
int bytesRead = 0;
int totalBytesRead = 0;
fileIn = new FileInputStream( file );
while( ( bytesRead = fileIn.read( buff, 0, buff.length ) ) > 0 ) {
System.arraycopy( buff, 0, fileBytes, totalBytesRead, bytesRead );
totalBytesRead += bytesRead;
}
}
}
finally {
if( fileIn != null ) { try { fileIn.close( ); } catch( Exception e ) { } }
}
return fileBytes;
}
}
/************************* End IOUtils.java ****************************/
tkrussel Guest



Reply With Quote

