gpt4 book ai didi

java - 在 com.google.Volley 上覆盖图像解析的最佳方法是什么?

转载 作者:行者123 更新时间:2023-11-30 03:17:03 27 4
gpt4 key购买 nike

我在单声道上使用 c# servicestack 开发了自己的 rest api。除了文件下载外,它按预期工作。我注意到它在文件开头附加了一些位。例如,请参见下图:this hexa representation of a downloaded image

我向 mono bugzilla 提交了错误,与此同时,我想覆盖客户端上的图像响应以删除第一个附加的内容以使图像正常工作。我通过在将接收到的流保存到文件之前对其进行编辑来在 C# 客户端上进行了尝试,它工作正常。

我需要知道如何以及在何处可以重写 volley 库以获得最佳性能的干净图像而不是畸形图像。

下午 4:37 更新:我相信我需要修改 com.android.volley.toolbox.ImageRequest >> 我会尝试它并发布解决方案,如果它适用于我。

问候,沙欣

最佳答案

我修改了com.android.volley.toolbox.ImageRequest中的doParse方法

private Response<Bitmap> doParse(NetworkResponse response){

byte[] data = response.data;
byte [] pattern = fromHexString("FFD8FFE000");
int position = matchPosition(data,pattern);
if(position>0)
data = Arrays.copyOfRange(data, position, data.length-position);
....
....
....
....
..}

这是我使用的辅助方法:

  public static int matchPosition(byte [] a, byte [] b){
int matchLength=0;
int maxSearch = 30>a.length?a.length:30;
for (int i =0;i<maxSearch;i++) {
if (a[i]==b[0] && i+b.length<a.length){
for(int j = 0;j< b.length;j++ )
{
if((i+j)==a.length-1)
return -1;
if(a[i+j]==b[j])
matchLength++;
}
if(matchLength == b.length)
return i;
else
matchLength = 0;
}
}
return -1;
}


private static byte[] fromHexString(final String encoded) {
if ((encoded.length() % 2) != 0)
throw new IllegalArgumentException("Input string must contain an even number of characters");

final byte result[] = new byte[encoded.length()/2];
final char enc[] = encoded.toCharArray();
for (int i = 0; i < enc.length; i += 2) {
StringBuilder curr = new StringBuilder(2);
curr.append(enc[i]).append(enc[i + 1]);
result[i/2] = (byte) Integer.parseInt(curr.toString(), 16);
}
return result;
}

这个解决方法解决了上面解释的问题!

关于java - 在 com.google.Volley 上覆盖图像解析的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19887782/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com