Oracle,blob字段存的转换成十六进制的jpg,怎么重新保存为图像?谢谢。 ( 积分: 5 )

  • 主题发起人 主题发起人 himoo
  • 开始时间 开始时间
H

himoo

Unregistered / Unconfirmed
GUEST, unregistred user!
先声明,这两天作东西,遇到的都是难题,分都发得差不多了,实在没有了。很对不起。以后补都可以!

保存在blob中的东西是这样的: 十六进制(jpg1)|十六进制(jpg2)|...
在数据库中察看是这样的:
FFD8FFE000104A46494600010101006000600000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C213232323......|FFD8FFE000104A46494600010101006000600000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC00011080053009503012200021101031101FFC4001F000001.....|
我首先把每段|分开,然后转换成字节,然后通过fileStream保存到jpg文件中,可是打开看的时候就是不对。不知道怎么回事。我有java实现的成功例子,可是我翻译成delphi后,就不成。。。

public static void main(String[] args) throws Exception {

//-----将十六进制字符串生成图片文件-----

String s = "";

byte[] ss = str.getByte(s);

FileOutputStream fw = new FileOutputStream("E://xcxc2.jpg");

fw.write(ss);

//----- END -----

}



public static byte[] getByte(String hexString) throws Exception {



if (hexString.length() % 2 != 0) {

return null;

}



byte[] bArray = new byte[hexString.length() / 2];

int j = 0;

for (int i = 0; i < hexString.length(); i += 2, j++) {

int high = charToNibble(hexString.charAt(i));

int low = charToNibble(hexString.charAt(i + 1));

bArray[j] = (byte) ((high << 4) | low);



}

return bArray;

}



private static int charToNibble(char c) {

if ('0' <= c &amp;&amp; c <= '9') {

return c - '0';

}

else if ('a' <= c &amp;&amp; c <= 'f') {

return c - 'a' + 0xa;

}

else if ('A' <= c &amp;&amp; c <= 'F') {

return c - 'A' + 0xa;

}

else {

throw new IllegalArgumentException(&quot;Invalid hex character: &quot; + c);

}

}
要完整的blob字段存的十六进制文本可以与我联系QQ174279,msn:himoo@live.com
 
后退
顶部