将QRCode转换为图像。 Java的

时间:2015-08-01 07:50:17

标签: java image

使用以下库:     qrgen-1.2,zxing-core-1.7,和     zxing-j2se-1.7我生成了QRCode:

    ByteArrayOutputStream out = QRCode.from(output.toString()).withSize(1000,1000).to(ImageType.PNG).stream();
    FileOutputStream fout = new FileOutputStream(new File("D:\\QR_Code.JPG"));
    fout.write(out.toByteArray());
    fout.flush();
    fout.close();

我打算用它做的是将代码发送到接受java.awt.Image的方法。 如何在不首先创建QRCode.JPG的情况下将QRCode类的实例转换为Image类的实例?正如我所看到的,这个库并没有为用户提供可以实现这一目标的方法,所以它有可能吗?可能我可以将流转换为Image吗?

1 个答案:

答案 0 :(得分:0)

只需将qr代码写入字节数组输出流,然后使用流中的字节数组创建Shader "Outlined/Silhouette2" { Properties { _Color("Color", Color) = (0,0,0,1) _MainColor("Main Color", Color) = (1,1,1,1) _Thickness("Thickness", float) = 4 _MainTex("Main Texture", 2D) = "white" {} } SubShader { Tags{ "Queue" = "Geometry" "IgnoreProjector" = "True" "RenderType" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha Cull Back ZTest always Pass { Stencil{ Ref 1 Comp always Pass replace } CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fog #include "UnityCG.cginc" struct v2g { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float3 viewT : TANGENT; float3 normals : NORMAL; }; struct g2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float3 viewT : TANGENT; float3 normals : NORMAL; }; float4 _LightColor0; sampler2D _MainTex; float4 _MainColor; v2g vert(appdata_base v) { v2g OUT; OUT.pos = mul(UNITY_MATRIX_MVP, v.vertex); OUT.uv = v.texcoord; OUT.normals = v.normal; OUT.viewT = ObjSpaceViewDir(v.vertex); return OUT; } half4 frag(g2f IN) : COLOR { //this renders nothing, if you want the base mesh and color //fill this in with a standard fragment shader calculation float4 texColor = tex2D(_MainTex, IN.uv); float3 normal = mul(float4(IN.normals, 0.0), _Object2World).xyz; float3 normalDirection = normalize(normal); float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz * -1); float3 diffuse = _LightColor0.rgb * _MainColor.rgb * max(0.0, dot(normalDirection, lightDirection)); texColor = float4(diffuse,1) * texColor; // //return texColor; return float4(0, 0, 0, 0); } ENDCG } Pass { Stencil{ Ref 0 Comp equal } CGPROGRAM #include "UnityCG.cginc" #pragma target 4.0 #pragma vertex vert #pragma geometry geom #pragma fragment frag half4 _Color; float _Thickness; struct v2g { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float4 local_pos: TEXCOORD1; float3 viewT : TANGENT; float3 normals : NORMAL; }; struct g2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float3 viewT : TANGENT; float3 normals : NORMAL; }; v2g vert(appdata_base v) { v2g OUT; OUT.pos = mul(UNITY_MATRIX_MVP, v.vertex); OUT.local_pos = v.vertex; OUT.uv = v.texcoord; OUT.normals = v.normal; OUT.viewT = ObjSpaceViewDir(v.vertex); return OUT; } [maxvertexcount(12)] void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream) { g2f OUT; OUT.pos = IN[0].pos; OUT.uv = IN[0].uv; OUT.viewT = IN[0].viewT; OUT.normals = IN[0].normals; triStream.Append(OUT); OUT.pos = IN[1].pos; OUT.uv = IN[1].uv; OUT.viewT = IN[1].viewT; OUT.normals = IN[1].normals; triStream.Append(OUT); OUT.pos = IN[2].pos; OUT.uv = IN[2].uv; OUT.viewT = IN[2].viewT; OUT.normals = IN[2].normals; triStream.Append(OUT); } half4 frag(g2f IN) : COLOR { _Color.a = 1; return _Color; } ENDCG } } FallBack "Diffuse" }

BufferedImage