日期:2014-05-18  浏览次数:20721 次

字符串生成图片
在oracle数据库中一字段是varchar2类型,它是以字符串的形式存储着一张图片,例如:47494638396110000C00E600008C5403FAEF5DDDB203F9F6D1D09807F5F1A3EFDA3BF5ED8CFFFFF69F671DD4A100EAC93DEFDC5C996600FBF675EDCC22D9AF26D4800BF5ECB4DB942FFFFFE7F3E880965B06E1932BF2EB67FEDF42D9A61DFFFF99FAFFB5F0E077DFC321E7C7419B4E00F5ED81F6FB62FFFBD9E09821FFFDA6FCF697FAFFC1E1A143FFE753E8E146EDD62AE1B916FEDF4DDB9931903E0EDC9C29D9A712EAD443995C03FFF4E1F8FDFF996633F7D83BFFEF6AFFD62FF7FBEFF8E868FFEE64FFF682FFFCBBFCFD8A986008FCF9AEFBF3BFFFF67CF7E147DCA6059C5405DAB017FFE338E39D30ECCF3CEFD1489E5806E59E28F8FA98F6DB37FEF053A2651EE0A12C974E0AFDFFC4DDA900FFFFFFFEFFD5FFFFB6E69431FFFFE0FEFFEEFFFFAAFFFC72FFE64DFFF76BFDFE80FFFF99FFE8449C6207F6FCD0F4EDB0F7CF1DFAEC6A9C5200FFFF66DE9C21E8B619DB9D3AEDD33FE2AD1FF6DB3FFFEC5DFFFFFF00000000000000000000000000000000000000000000000000000000000000000000000000000000000021F90405140071002C0000000010000C000007B8801149833030138788832E534D085656353508085B9523973E5124273A8F5614575458254E3F696B006C122A058F5AA1585C1B0C45024630560332155A5A27275C3F1F470F39408D56343B2B425758212C55375044B7081456264B2B1D0B0A040622671963173A08076D23254A1E2D01104F0E19331356074A031C411B1B60603834BC41020485042564B0F0EB376448170C6ECC8C9152C6448F1E5F70E0809322851831446230016123C18C9340809C3C69648C91178100003B

现在我想知道怎么根据字符串生成一张图片,这个问题一直解决不了,请高人帮忙下

------解决方案--------------------
一般没有使用varchar2来保存二进制类型的,
这里的应该是二进制表示的字符序列,将这个字符序列还原为byte数组,之后构建为image看看吧

------解决方案--------------------
String s = ...;
OutputStream os = new FileOutputStream( "C:/A.gif ");
for(int i = 0; i < s.length(); i+=2) {
os.write(Integer.parseInt(s.substring(i, i + 2), 16));
}
os.close();

------解决方案--------------------
String s = ...;
OutputStream os = new FileOutputStream( "C:/A.gif ");
for(int i = 0; i < s.length(); i+=2) {
os.write(Integer.parseInt(s.substring(i, i + 2), 16));
}
os.close();

--------------------------------
请问我不用在本地保存此图片,直接在页面显示这张图片应该怎么做?
=============================================================
文件都生成了,还愁放不上吗?要我说直接<img src= "C:/A.gif ">
可能我这个最垃圾,嗬嗬,不知道是否还有高招
------解决方案--------------------
response.setContentType( "image/tif ");

String s = ...;
OutputStream os = response.getOutputStream();
for(int i = 0; i < s.length(); i+=2) {
os.write(Integer.parseInt(s.substring(i, i + 2), 16));
}

os.close();