Criar matriz de byte atraves de uma String

27/05/2008

2

Galera, seguinte tenho uma imagem que é guardada em uma matriz do tipo byte, ela é assim:

const byte RPrint [] = {
0x01, 0x01, 0x01, 0x31, 0x00, 0x30, 0x38, 0x30, 0x02, 0x20, 0x89, 0xE0, 0xE3, 0xF0, 0xF9, 0xFD,
0xFD, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFC, 0xF8, 0xF8, 0xF0, 0xE2, 0xE4, 0xDE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x50, 0x80, 0x20, 0x04, 0x03, 0x84, 0xF3, 0xFA, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xBF, 0x3F, 0x3F, 0x7F, 0xBF,
0x3F, 0x3F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0x3F, 0x3F, 0x3F, 0x7F, 0x3F, 0x3F, 0xBF, 0x3F, 0x7F, 0x3F, 0x3F´ ....

como faria para montar cada codigo hexa dentro de uma posição de minha matriz
tipo eu tenho ela criada zerada byte RPrint [];
tem alguma maneira de fazer isso?
pq eu uso a variavel RPrint para imprimir a imagem....

Obrigado desde jah!


Responder

Posts

28/05/2008

Rodc

Usando C++ Builder:

O código abaixo faz o que você quer. Só que a função HexToInt() não existe. Mas como você é um cara esperto, vai dar uma olhada na net e descobrir como converte Hexa para Inteiro.
AnsiString StringImagem = "0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7F, 0x3F, 0x3F, 0xBF, 0x3F, 0x7F, 0x3F, 0x3F";
TStringList *lista = new TStringList();
lista->CommaText = StringImagem;

byte *vetor = new byte[lista->Count];

for (int x=0; x<lista->Count; x++) {
    AnsiString valorHexa = lista->Strings[x].Trim().SubString(3, 2);
    vetor[x] = HexToInt(valorHexa);
}

delete[] vetor;
delete lista;



Responder

29/05/2008

Darkducke

Usando C++ Builder: O código abaixo faz o que você quer. Só que a função HexToInt() não existe. Mas como você é um cara esperto, vai dar uma olhada na net e descobrir como converte Hexa para Inteiro.
AnsiString StringImagem = "0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7F, 0x3F, 0x3F, 0xBF, 0x3F, 0x7F, 0x3F, 0x3F";
TStringList *lista = new TStringList();
lista->CommaText = StringImagem;

byte *vetor = new byte[lista->Count];

for (int x=0; x<lista->Count; x++) {
    AnsiString valorHexa = lista->Strings[x].Trim().SubString(3, 2);
    vetor[x] = HexToInt(valorHexa);
}

delete[] vetor;
delete lista;


Tem que ser em C,
um colega passou uma função, soh que o problema ta quando passo a variavel char para a variavel byte.. quando mando imprimir não sai o esperado, ou seja, os 0x00 não estão sendo inseridos como hexa....

=/


Responder

30/05/2008

Rodc

Quando você tenta imprimir uma sequência de caracteres que tem 0x00 no meio da sequência, ele pára de imprimir no caracter zerado.
Se quizer poste o código aqui que eu tendo dar uma olhada.


Responder
×
+1 DevUP
Acesso diário, +1 DevUP
Parabéns, você está investindo na sua carreira