简体   繁体   中英

How do I load an ARGB_8888 Image with a normal DataInputStream?

Edited: Thanks for the previous answers and help! I've decided to edit this question into what I need exactly, sorry for not being as specific earlier.

Basically the title is all the information, this is currently what I'm working with:

int channels = 4;
int length = width * height;
int[] data = new int[length * channels];
int[][] channelPixels = new int[4][length];

for (int c = 0; c < channels; c++) {
    for (int i = 0; i < length; i++) {
        channelPixels[c][i] = readByte();
    }
}

Unfortunately, the colors don't seem to match up to the originals.

Is there something I'm doing wrong here?

Cardinal is an unsigned integer, and Typename(value) is Delphi syntax for a typecast. (The equivalent in C syntax is (typename) value .) So Cardinal() isn't a function, it's casting the pointers as unsigned integers.

As a few people have already pointed out the ^ operator is a pointer dereference operator. dp^ := sp^ means "Set the value that dp points to equal to the value that sp is pointing to."

Pointers and pointer incrementing, such as is being used here, don't exist in Java, so this makes your job a lot trickier. What you need to do if you want to do this in managed code is rewrite the entire thing in terms of arrays.

This code flips rectangular buffer and changes RGBA byte order to BGRA (or vice versa) like this:

a b c d e f g h
i j k l m n o p
=>
k j i l o n m p
c b a d g f e h

Rough analog with c/java-like pseudocode:

src = array of byte with length (RawHdr.Width * RawHdr.Height * 4)
dst = array of byte with the same length

dstindex = 0

for (i = RawHdr.Height - 1; i >= 0; i--)
    {
     srcstartindex = i * RawHdr.Width * 4;
     for (j = 0; j < RawHdr.Width; j++)
         {  
           si = srcstartindex + j * 4;
           dst[dstindex] = src[si + 2];
           dst[dstindex + 1] = src[si + 1];
           dst[dstindex + 2] = src[si];
           dst[dstindex + 3] = src[si + 3];
           dstindex +=4;
         }
     } 

I am not going to write your code for you but these should help you:

Cardinal , from the first link on Google, it is the basic unsigned integer type with a size that is not guaranteed.

^ is a pointer dereference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM