目前在要在区块链上存储图片有两种模式:
1.对于eth等公链,把图片存储到IPFS上,得到图片的hash,然后将hash存储在区块链上。
2.对于自己的公链,可以把图片存储在本地服务器,计算hash,然后将hash存储在区块链上。
There are currently two modes of storing pictures on a block chain:
1. For a public chain like Eth, store pictures on an IPFS, get a picture of the hash, and then store the hash on a block chain.
2. For your own public chain, you can store pictures on a local server, calculate the hash, and then store the hash on the chain.
那么能不能直接将图片存储区块链上呢?
So can you just put the picture on the chain?
最近接触了一个公链,一个区块的大小是32k,那么理论上可以将小于32k的图片先进行base64编码,然后直接存储在区块链上,这样对于开发者和使用者都简单。
但是现在一般都是高清的大图,如何将图片压缩到32k以下,就是需要思考的问题。
解决办法:
1.使用高压缩比的压缩算法,这个目前有一些算法,需要验证。
2.将图片分开存储,这个需要根据具体情况设计。
因此先选择第一种方法,看看效果。
以下是java版的图片压缩算法,可以将图片进行一定比例的压缩。
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
Recently exposed to a public chain, a block size of 32k, which would theoretically allow images smaller than 32k to be coded first and stored directly on the block chain, which would be simple for developers and users.
, but it is now generally high-level maps, and how to compress pictures below 32k is a question to think about.
Solutions:
1. Use high-compressive compression algorithms, which currently have some algorithms that need to be validated.
2. Separate images that need to be designed on a case-by-case basis.
So select the first method, see the effects.
Below is the Java version of photo compression algorithms, which can be proportionally compressed.
// 将一个字符串按照zip方式压缩和解压缩
public class ZipUtil {
// Compress a string
public class ZipUtil {
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论