简体   繁体   English

如何使用正常的DataInputStream加载ARGB_8888图像?

[英]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. Cardinal是一个无符号整数, Typename(value)Typename(value) Delphi语法。 (The equivalent in C syntax is (typename) value .) So Cardinal() isn't a function, it's casting the pointers as unsigned integers. (C语法中的等效项是(typename) value 。)所以Cardinal()不是函数,它将指针转换为无符号整数。

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." dp^ := sp^意思是“将dp指向的值设置为等于sp指向的值。”

Pointers and pointer incrementing, such as is being used here, don't exist in Java, so this makes your job a lot trickier. 指针和指针递增(例如在这里使用的)在Java中不存在,因此这会使您的工作变得更加棘手。 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: 此代码翻转矩形缓冲区,并将RGBA字节顺序更改为BGRA(反之亦然),如下所示:

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: 类似于c / java的伪代码的粗略模拟:

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. Cardinal从Google的第一个链接开始,它是基本的无符号整数类型,其大小不能保证。

^ is a pointer dereference. ^是指针取消引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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