Converting bytes to pixels???
Hi Everyone,
My Jdev version is 11.1.2.3.0.
I have deloped one ADF applicaton which is working fine.
Now i have added a table to the page which has 3 columns. The width of the column in ADF page should be equal to width of the column in the database.
How can i convert bytes to pixels in my ADF page.
The three column's width in database are: 200Bytes, 250Bytes, 150Bytes. Now i need to specify the width in pixels in ADF.
how can i do that?
Any ways to do that?
Thanks.
Yeah I meant e[i] - sorry about that.
When you say "diagram the to / from arrays" do you mean you want to see their definition & initialisation? If so, please see below:
numBands, length & width are the three fields read in from the image header.
byte[] imageDataByte = new byte[numBands * length * width];
ra.read(imageDataByte,0,numBands * length * width);
int[] iD = new int[numBands * length * width];
int count = 0;
int[] imageData = new int[numBands * length * width];
for (int x = 0; x < length; x++)
for (int y = 0; y < numBands; y++)
for (int z = 0; z < width; z++)
imageData[(length*z+x) + (length* width*y)] += imageDataByte[(length*z+x) + (length* width*y)] << ((length*z+x) + (length* width*y)*512);
count = count + 1;
System.out.println(count + ": " + imageData[(length*z+x) + (length* width*y)]);
Any help would be greatly appreciated.
Many thanks,
CG.
Similar Messages
-
Convert byte array to table of int
[http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print|http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print] Hello friends.
I'm pretty new with PL/SQL.
I have code that run well on MSSQL and I want to convert it to PL/SQL with no luck.
The code converts byte array to table of int.
The byte array is actually array of int that was converted to bytes in C# for sending it as parameter.
The TSQL code is:
CREATE FUNCTION dbo.GetTableVarchar(@Data image)
RETURNS @DataTable TABLE (RowID int primary key IDENTITY ,
Value Varchar(8000))
AS
BEGIN
--First Test the data is of type Varchar.
IF(dbo.ValidateExpectedType(103, @Data)<>1) RETURN
--Loop thru the list inserting each
-- item into the variable table.
DECLARE @Ptr int, @Length int,
@VarcharLength smallint, @Value Varchar(8000)
SELECT @Length = DataLength(@Data), @Ptr = 2
WHILE(@Ptr<@Length)
BEGIN
--The first 2 bytes of each item is the length of the
--varchar, a negative number designates a null value.
SET @VarcharLength = SUBSTRING(@Data, @ptr, 2)
SET @Ptr = @Ptr + 2
IF(@VarcharLength<0)
SET @Value = NULL
ELSE
BEGIN
SET @Value = SUBSTRING(@Data, @ptr, @VarcharLength)
SET @Ptr = @Ptr + @VarcharLength
END
INSERT INTO @DataTable (Value) VALUES(@Value)
END
RETURN
END
It's taken from http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print.
The C# code is:
public byte[] Convert2Bytes(int[] list)
if (list == null || list.Length == 0)
return new byte[0];
byte[] data = new byte[list.Length * 4];
int k = 0;
for (int i = 0; i < list.Length; i++)
byte[] intBytes = BitConverter.GetBytes(list);
for (int j = intBytes.Length - 1; j >= 0; j--)
data[k++] = intBytes[j];
return data;
I tryied to convert the TSQL code to PL/SQL and thats what I've got:
FUNCTION GetTableInt(p_Data blob)
RETURN t_array --t_array is table of int
AS
l_Ptr number;
l_Length number;
l_ID number;
l_data t_array;
BEGIN
l_Length := dbms_lob.getlength(p_Data);
l_Ptr := 1;
WHILE(l_Ptr<=l_Length)
loop
l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
IF(l_ID<-2147483646)THEN
IF(l_ID=-2147483648)THEN
l_ID := NULL;
ELSE
l_Ptr := l_Ptr + 4;
l_ID := to_number( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
END IF;
END IF;
l_data(l_data.count) := l_ID;
l_Ptr := l_Ptr + 4;
END loop;
RETURN l_data;
END GetTableInt;
This isn't work.
This is the error:
Error report:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
06502. 00000 - "PL/SQL: numeric or value error%s"
I think the problem is in this line:
l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
but I don't know how to fix that.
Thanks,
MTs.I'd found the solution.
I need to write:
l_ID := utl_raw.cast_to_binary_integer( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
instead of:
l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
The performance isn't good, it's take 2.8 sec to convert 5000 int, but it's works. -
Converting byte[] to Class without using defineClass() in ClassLoader
so as to de-serialize objects that do not have their class definitions loaded yet, i am over-riding resolveClass() in ObjectInputStream .
within resolveClass() i invoke findClass() on a network-based ClassLoader i created .
within findClass() , i invoke
Class remoteClass = defineClass(className, classImage, 0, classImage.length);
and that is where i transform a byte[] into a Class , and then finally return a value for the resolveClass() method.
this seems like a lengthy process. i mean, within resolveClass() i can grab the correct byte[] over the network.
then, if i could only convert this byte[] to a Class within resolveClass() , i would never need to extended ClassLoader and over-ride findClass() .
i assume that the only way to convert a byte[] to a Class is using defineClass() which is hidden deep within ClassLoader ? there is something going on under the hood i am sure. otherwise, why not a method to directly convert byte[] to a Class ? the byte[] representation of a Class always starts with hex CAFEBABE, and then i'm sure there is a standard way to structure the byte[] .
my core issue is:
i am sending objects over an ObjectInputStream created from a Socket .
at the minimum, i can see that resolveClass() within ObjectInputStream must be invoked at least once .
but then after that, since the relevant classes for de-serialization have been gotten over the network, i don't want to cascade all the way down to where i must invoke:
Class remoteClass = defineClass(className, classImage, 0, classImage.length);
again. so, right now, within resolveClass() i am using a Map<String, Class> to create the following class cache:
cache.put(objectStreamClass.getName(), Class);
once loaded, a class should stay loaded (even if its loaded in the run-time), i think? but this is not working. each de-serialization cascades down to defineClass() .
so, i want to short-circuit the need to get the class within the resolveClass() method (ie. invoke defineClass() only once),
but using a Map<String, Class> cache looks really stupid and certainly a hack.
that is the best i can do to explain my issue. if you read this far, thanks.ok. stupid question:
for me to use URLClassLoader , i am going to need to write a bare-bones HTTP server to handle the class requests, right?Wrong. You have to deploy one, but what's wrong with Apache for example? It's free, for a start.
and, i should easily be able to do this using the com.sun.net.httpserver library, right?Why would you bother when free working HTTP servers are already available? -
Converting byte from dec to hex
Hi All,
I'm having a problem converting byte from decimal to hex - i need the following result:
if entered 127 (dec), the output should be 7f (hex).
The following method fails, of course because of NumberFormatException.
private byte toHexByte(byte signedByte)
int unsignedByte = signedByte;
unsignedByte &= 0xff;
String hexString = Integer.toHexString(unsignedByte);
BigInteger bigInteger = new BigInteger(hexString);
//byte hexByte = Byte.parseByte(hexString);
return bigInteger.byteValue();
}get numberformatexception because a lot of hex digits cannot be transformed into int just like that (ie f is not a digit in decimal) heres some code that i used for a pdp11 assembler IDE... but this is for 16-bit 2s complement in binary/octal/decimal/hex , might be useful for reference as example though
public static String getBase(short i, int base){
String res = (i>=0)? Integer.toString((int)i,base)
: Integer.toString((int)65536+i,base) + " ("+Integer.toString((int)i,base)+")";
StringBuffer pad= new StringBuffer();
for(int x = 0; x < 16 - res.length() ; x++){
pad.append("0");
res = pad.toString() + res;
return res;
} -
Problem using byte indexed pixel format in setPixels method of PixelWriter
I try to construct a byte array and set it to a WritableImage using PixelWriter's setPixels method.
If I use an RGB pixel format, it works. If I use a byte-indexed pixel format, I get an NPE.
The stride etc should be fine if I'm not mistaken.
java.lang.NullPointerException
at com.sun.javafx.image.impl.BaseByteToByteConverter.<init>(BaseByteToByteConverter.java:45)
at com.sun.javafx.image.impl.General$ByteToByteGeneralConverter.<init>(General.java:69)
at com.sun.javafx.image.impl.General.create(General.java:44)
at com.sun.javafx.image.PixelUtils.getB2BConverter(PixelUtils.java:223)
at com.sun.prism.Image$ByteAccess.setPixels(Image.java:770)
at com.sun.prism.Image.setPixels(Image.java:606)
at javafx.scene.image.WritableImage$2.setPixels(WritableImage.java:199)
Short, self-contained example here:
import java.nio.ByteBuffer;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class IndexedColorTestApp extends Application {
public static void main(String[] args) {
launch(args);
@Override
public void start(Stage primaryStage) {
BorderPane borderPane = new BorderPane();
Scene scene = new Scene(borderPane, 600, 1100);
primaryStage.setScene(scene);
ImageView imageView = new ImageView();
borderPane.setCenter(imageView);
primaryStage.show();
int imageWidth = 200;
int imageHeight = 200;
WritableImage writableImage = new WritableImage(imageWidth, imageHeight);
// this works
byte[] rgbBytePixels = new byte[imageWidth * imageHeight * 3];
PixelFormat<ByteBuffer> byteRgbFormat = PixelFormat.getByteRgbInstance();
writableImage.getPixelWriter().setPixels(0, 0, imageWidth, imageHeight,
byteRgbFormat, rgbBytePixels, 0, imageWidth * 3);
imageView.setImage(writableImage);
// this throws an NPE in setPixels()
byte[] indexedBytePixels = new byte[imageWidth * imageHeight];
int[] colorPalette = new int[256];
PixelFormat<ByteBuffer> byteIndexedFormat = PixelFormat.createByteIndexedInstance(colorPalette);
writableImage.getPixelWriter().setPixels(0, 0, imageWidth, imageHeight,
byteIndexedFormat, indexedBytePixels, 0, imageWidth);
imageView.setImage(writableImage);
}If there's no solution, maybe someone knows a workaround? We chose to use indexed format because of data size / performance reasons.
Edited by: Andipa on 01.03.2013 10:52You have found a platform bug, file it against the Runtime project at => http://javafx-jira.kenai.com with your sample code and a link back to this forum question.
Byte indexed pixel formats seem like a feature which was never completely (or perhaps even hardly at all) implemented to me.
The PixelFormat type your failed case is using is (PixelFormat.Type.BYTE_INDEXED):
PixelFormat<ByteBuffer> byteIndexedFormat = PixelFormat.createByteIndexedInstance(colorPalette);
System.out.println(byteIndexedFormat.getType());These are the valid PixelFormat types =>
http://docs.oracle.com/javafx/2/api/javafx/scene/image/PixelFormat.Type.html
BYTE_BGRA
The pixels are stored in adjacent bytes with the non-premultiplied components stored in order of increasing index: blue, green, red, alpha.
BYTE_BGRA_PRE
The pixels are stored in adjacent bytes with the premultiplied components stored in order of increasing index: blue, green, red, alpha.
BYTE_INDEXED
The pixel colors are referenced by byte indices stored in the pixel array, with the byte interpreted as an unsigned index into a list of colors provided by the PixelFormat object.
BYTE_RGB
The opaque pixels are stored in adjacent bytes with the color components stored in order of increasing index: red, green, blue.
INT_ARGB
The pixels are stored in 32-bit integers with the non-premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.
INT_ARGB_PRE
The pixels are stored in 32-bit integers with the premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.As the native pixel format for a WritableImage is not the same as the pixel format you are using, the JavaFX platform needs to do a conversion by reading the pixels in one format and writing them in another format. To do this it must be able to determine a PixelGetter for your PixelFormat (the PixelGetter is an internal thing, not public API).
And here is the source the determines the PixelGetter for a given PixelFormat type:
http://hg.openjdk.java.net/openjfx/8/master/rt/file/06afa65a1aa3/javafx-ui-common/src/com/sun/javafx/image/PixelUtils.java
119 public static <T extends Buffer> PixelGetter<T> getGetter(PixelFormat<T> pf) {
120 switch (pf.getType()) {
121 case BYTE_BGRA:
122 return (PixelGetter<T>) ByteBgra.getter;
123 case BYTE_BGRA_PRE:
124 return (PixelGetter<T>) ByteBgraPre.getter;
125 case INT_ARGB:
126 return (PixelGetter<T>) IntArgb.getter;
127 case INT_ARGB_PRE:
128 return (PixelGetter<T>) IntArgbPre.getter;
129 case BYTE_RGB:
130 return (PixelGetter<T>) ByteRgb.getter;
131 }
132 return null;
133 }As you can see, the BYTE_INDEXED format is not handled and null is returned instead . . . this is the source of your NullPointerException. -
Function module to convert byte stream to Tiff formate.
Hi All,
Is there any function module is there to convert byte stream to Tiff formate.
Thanks®ds,
Srinivas.
Edited by: srinivas balla on Dec 24, 2007 6:28 AMtry this
SCP_1TO1_BYTE_CONVERTER_MAP
Award Points if useful
bhupal -
How to convert bytes[] into File object
hi
how to convert byte array into File object
pls.. help me
Regards
srinurrrr007 wrote:
Hi,
How to convert bytes[] into multipage File object?? ]There's no such thing as a "multipage File object." You ought to re-read this thread closely, and read the [API docs for File|http://java.sun.com/javase/6/docs/api/java/io/File.html] to clear up your confusion about what a File object is.
I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream. Then you need a pdf API, like iText or fop. You can't just concatenate pdf files, word docs, excel sheets, etc., like you can text files. Google for java pdf api. -
How to convert byte into string
can any tell me how to convert byte into string
when im an debugging thid code in eclipse it shows the result in integer format instead of string but in command prompt it is showing result in string format..........plz help
package str;
import java.io.*;
public class Testfile {
public static void main(String rags[])
byte b[]=new byte[100];
try{
FileInputStream file=new FileInputStream("abc.txt");
file.read(b,0,50);
catch(Exception e)
System.out.println("Exception is:"+e);
System.out.println(b);
String str=new String(b);
System.out.println(str);
}Namrata.Kakkar wrote:
errors: count cannot be resolved and Unhandled exception type Unsupported Encoding Exception.
If i write an integer value instead of "count" then Unhandled exception type Unsupported Encoding Exception error is left.This is elementary. You need to go back to [http://java.sun.com/docs/books/tutorial/|http://java.sun.com/docs/books/tutorial/] . -
How to convert bytes[] into multipage File object
Hi,
How to convert bytes[] into multipage File object??
I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream.
Thanks for you help in advance..Only text format allows you to concatenate two files together to get a longer files.
Most formats have a header and a footer and so you cannot simply add one to the other.
You need to use a PDF API which will allow you to build the new document (if one exists) -
Converting byte[] to unicode , help needed.
need help, folks.
i need to convert byte[] to unicode in byte[] form
say i already loaded bunch of data
byte[] bytes = {........} //bunch array of bytesand i read in the bytes as a stream in the native form.
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
InputStreamReader isr = new InputStreamReader(stream,"GB18030");how do i get the bytes back in unicode ? i've been trying all kinds of methods, but doesnt seems to get what i want. i'm novice programmer, someone pls guide me ? thx.String s ;
StringBuffer buffer = new StringBuffer();
try {
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
InputStreamReader isr = new InputStreamReader(stream, "GB18030");
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
buffer.append((char)ch);
in.close();
s = buffer.toString();
bytes = s.getBytes("UnicodeLittle");
out.write(bytes);
} catch (IOException e) {
e.printStackTrace();
//return null;
}ah, nvm, i found a better solution to it, i'm little confused before this. the code above works fine.
well, thx alot. -
Is there an easier way to convert bytes into bit(boolean) arrays?
I am currently using this method to convert bytes into bit arrays:
/*convert byte to int such that it is between 0-255 this is the bytes[] array
if ((bytes/128)==1)
bit[c+0]=true;
else
bit[c+0]=false;
if ((bytes[i]-bitInt[c+0]*128)/64==1)
bit[c+1]=true;
else
bit[c+1]= false;
if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64)/32==1)
bit[c+2]=true;
else
bit[c+2]= false;
if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32)/16==1)
bit[c+3]=true;
else
bit[c+3]= false;
if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16)/8==1)
bit[c+4]=true;
else
bit[c+4]= false;
if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16-bitInt[c+4]*8)/4==1)
bit[c+5]=true;
else
bit[c+5]= false;
if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16-bitInt[c+4]*8-bitInt[c+5]*4)/2==1)
bit[c+6]=true;
else
bit[c+6]= false;
if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16-bitInt[c+4]*8-bitInt[c+5]*4-bitInt[c+6]*2)==1)
bit[c+7]=true;
else
bit[c+7]= false;You can loop through and use a bitwise operator instead. Here is an example without the loop.
byte b = 6 ;
if( b & Math.pow( 2, 0 ) == Math.pow( 2, 0 ) ) ;
// the 2^0 bit is on
if( b & Math.pow( 2, 1 ) == Math.pow( 2, 1 ) ) ;
// the 2^1 bit is onetc...
You should get something like 110 when you're done.
If you're wonder what & does (no, its not a boolean &&), it takes the bits in the two numbers you give it and returns a number with all the bits on that are on for each of them.
For example:
10011011 &
11001101 =
10001001
So if we take
110 (6) &
010 (2^1, or 2) =
010 (2 again)
Which means that the number (6) has the 2^1 bit on. -
Need to convert byte[] to image
hi frnds,
i have a byte[](which i got it from an image) i need to convert back to image.Could u pls suggest me how to??
i tried with Pixelgrabber but i exaclty did get wht shld be the input for it(tried giving image file name). :(
So pls let me know how and wht to use..ASAP.
Regards
subinjavaSubinjava wrote:
..i have a byte[](which i got it from an image) i need to convert back to image.Could u pls suggest me how to??
Image image = Toolkit.getDefaultToolkit().createImage(byteArray)See http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#createImage(byte[]) for more details. -
Converting bytes to character array problem
I am trying to convert a byte array into a character array, however no matter which Character Set i choose i am always getting the '?' character for some of the bytes which means that it was unable to convert the byte to a character.
What i want is very simple. i.e. map the byte array to its Extended ASCII format which actually is no change in the bit represtation of the actual byte. But i cannot seem to do this in java.
Does anyone have any idea how to get around this problem?Thanks for responding.
I have however arrived at a solution. A little un-elegant but it seems to do the job.
I am converting each byte into char manually by this algorithm:
for (int i=0;i<compressedDataLength;i++)
if (((int) output)<0)
k=(127-((int) output[i]));
outputChr[i]=((char) k);
else
k=((int) output[i]);
outputChr[i]=((char) k);
System.out.println(k);
where output is the byte array and outputChr is the character array -
Converting byte[] to short, long, etc.
I need to packetize the data with my own header embedded in the data. The header field is composed of data types: short, byte, and long. Since the header will be transported over the network using UDP socket, it will have to be converted to type byte[].
Is there a clean way to convert from byte[] to short, and long data types? Or do I have to concatenate bytes and type cast them? How do I even type cast byte[] to short? Thanks.Have a look at the ByteBuffer class. You can wrap a byte
array in such a buffer and write other types (like ints or longs etc)
to the byte array through the buffer. Of course you can read those
values back again using the buffer.
kind regards,
Jos -
Problems converting byte[] to string
I use
byte[] encryptedBytes = cipher.doFinal(bytesToEncrypt);
String Ciphertext = new String(encryptedBytes);
and sometimes i get the correct answer ans sometimes no. If yo want the code is in this post:
http://forum.java.sun.com/thread.jspa?threadID=790137&start=15&tstart=0That's because the C language lacks true character and string data types. It only has arrays of bytes. Unfortunately in C bytes are misleadingly called "chars."
It works if you put ASCII because byte sequences that correspond to ASCII characters can, on most systems, be safely converted to characters and strings. You see, conversions from bytes to characters are done using things called "encoding schemes" or just encodings. If you don't specify an encoding, the system's default is used. The default encoding can be pretty much anything so it's best not to assume much about it.
You can also use a fixed encoding, like this:String Ciphertext = new String(encryptedBytes, "ISO-8859-1");Just remember that when you convert the string back to bytes you have to use the same encoding again, that isbyte[] cipherBytes = cipherString.getBytes("ISO-8859-1");
Maybe you are looking for
-
Wscompile does not seem to be generating a client stub
When I run the wscompile tool on a WSDL file generated using gSoap the wscompile tool does not generate the client stub. Instead it reports the following errors: warning: ignoring port "finsvc": no SOAP address specified warning: Service "finsvc" doe
-
Error while Creating Report Region using APEX_ITEM
Hello Friends, I am trying to make a Cascading Select List in Tabular Form. but getting error while compiling the region source: Error : Query cannot be parsed, please check the syntax of your query. (ORA-00907: missing right parenthesis) Can some on
-
Hello folks: This is my first post. I'm working on just my second project in iMovie, so I hope I'm not asking something obvious, but I didn't see it in the documentation or in several pages of posts here. This is the first time I've experimented with
-
Transfer my LR4 from Crashed computer to new one.
I purchased LR4 from Adobe's site and last week my Apple went down. I bought a new Apple, can I use my serial number to download to new computer?
-
Hi Experts, I need a tool to convert XML message to EDI.