android位图不是从base64创建的(android bitmap isn't created from base64)
我有一个Android应用程序,它将图像发送到Web服务。 我想将相同的照片从Web服务发送回Android。
我做了一个测试程序来比较从Android发送到服务器的base64数据和从服务器发送回Android的base64 - 它们完全相同。
我想使用base 64字符串来创建位图,所以我尝试了这个:
String image = client1.getBaseURI("restaurantFoods/OneFood/" + this.getID() + "/getImage"); byte[] decodedString = Base64.decode(image, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); if(decodedByte == null){ Log.d(this.getFoodItem().getName(), image); Log.d("isNull", "Yes"); } else{ Log.d("isNull", "No");}
我一直都是null,因为日志只打印“YES”。
有人可以帮忙吗?
如果您想知道我如何编码图像,它如下:
private String getBase64(Bitmap bitmap) { String imgString = Base64.encodeToString(getBytesFromBitmap(bitmap), Base64.NO_WRAP); return imgString; } private byte[] getBytesFromBitmap(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 70, stream); return stream.toByteArray(); } Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.drawable.pizza); String iconBase64 = this.getBase64(icon);
I have an Android application which sends an image to a web service. I want to send the same photo back from the web service to Android.
I made a test program to compare the base64 data that's sent from Android to the server and the base64 that's sent back from server to Android -- they are exactly equal.
I want to use the base 64 string to create a bitmap, so I tried this:
String image = client1.getBaseURI("restaurantFoods/OneFood/" + this.getID() + "/getImage"); byte[] decodedString = Base64.decode(image, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); if(decodedByte == null){ Log.d(this.getFoodItem().getName(), image); Log.d("isNull", "Yes"); } else{ Log.d("isNull", "No");}
I keep getting null because the log just prints "YES".
Can anyone please help?
If you want to know how I encode the image it is as follows:
private String getBase64(Bitmap bitmap) { String imgString = Base64.encodeToString(getBytesFromBitmap(bitmap), Base64.NO_WRAP); return imgString; } private byte[] getBytesFromBitmap(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 70, stream); return stream.toByteArray(); } Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.drawable.pizza); String iconBase64 = this.getBase64(icon);
原文:https://stackoverflow.com/questions/16966656
最满意答案
因为语言标准的第6.4.4.2节“浮动常量”因此定义它们:
floating-constant: decimal-floating-constant hexadecimal-floating-constant decimal-floating-constant: fractional-constant exponent-part(opt) floating-suffix(opt) digit-sequence exponent-part floating-suffix(opt) hexadecimal-floating-constant: hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part floating-suffixopt hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part floating-suffix(opt) fractional-constant: digit-sequence(opt) . digit-sequence digit-sequence . exponent-part: e sign(opt) digit-sequence E sign(opt) digit-sequence sign: one of + - digit-sequence: digit digit-sequence digit hexadecimal-fractional-constant: hexadecimal-digit-sequence(opt) . hexadecimal-digit-sequence hexadecimal-digit-sequence . binary-exponent-part: p sign(opt) digit-sequence P sign(opt) digit-sequence hexadecimal-digit-sequence: hexadecimal-digit hexadecimal-digit-sequence hexadecimal-digit floating-suffix: one of f l F L
最重要的是,以下所有内容都是有效的浮点文字,意思是“零”:
0。
0.0
0.0
(你的“100”将是一个有效的
floating-constant
,因为它是一个decimal-floating-constant
由一个fractional-constant
decimal-floating-constant
组成(省略了可选的exponent-part
和floating-suffix
);它是一个digit-sequence
后跟一个句点,对于一个fractional-constant
有效,如该noteable定义的第二行。)Because section 6.4.4.2 of the language standard, "Floating constants" , defines them thusly:
floating-constant: decimal-floating-constant hexadecimal-floating-constant decimal-floating-constant: fractional-constant exponent-part(opt) floating-suffix(opt) digit-sequence exponent-part floating-suffix(opt) hexadecimal-floating-constant: hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part floating-suffixopt hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part floating-suffix(opt) fractional-constant: digit-sequence(opt) . digit-sequence digit-sequence . exponent-part: e sign(opt) digit-sequence E sign(opt) digit-sequence sign: one of + - digit-sequence: digit digit-sequence digit hexadecimal-fractional-constant: hexadecimal-digit-sequence(opt) . hexadecimal-digit-sequence hexadecimal-digit-sequence . binary-exponent-part: p sign(opt) digit-sequence P sign(opt) digit-sequence hexadecimal-digit-sequence: hexadecimal-digit hexadecimal-digit-sequence hexadecimal-digit floating-suffix: one of f l F L
Bottom line, all of the following would be valid floating point literals meaning "zero":
0.
.0
0.0
(Your "100." would be a valid
floating-constant
, as it is adecimal-floating-constant
consisting of afractional-constant
(omitting the optionalexponent-part
andfloating-suffix
); it is adigit-sequence
followed by a period, which is valid for afractional-constant
as by the second line of that noteable's definition.)
相关问答
更多-
citizen手表价格最少多少钱[2023-10-20]
100 -
回答https://stackoverflow.com/a/15752736帮助我发现Mongo不想在没有正确设置区域设置的情况下启动。 尝试在meteor命令之前运行export LC_ALL="en_US.UTF-8"命令。 Answer https://stackoverflow.com/a/15752736 helped me to find out that Mongo doesn't want to start without properly set locale. Try to run ex ...
-
十二个软件开发的法律注意事项 软件版权归公众所有。 不再需要在应用程序或源代码中放置版权声明。 版权所有者是付款作者的作者或公司。 软件的版权可以由版权所有者分配,也可以由所有者保留,软件可以由所有者授权给用户或用户。 在开发中使用的图书馆可能对其使用和分发有限制。 GPL不会创建图书馆的公共领域,图书馆也不附带开发平台。 在您分发应用程序之前,您应该阅读并了解许可证。 一些图书馆需要使用特许权使用费,尽管近年来这些图书馆不太常见。 软件专利诉讼是废话。 当然,您不应该明知违反软件专利。 但是,有一些公司会 ...
-
我们可以隐藏iPhone 5(苹果)地图中的法律文本吗?(Can we hide the legal text in iPhone 5 (apple) maps? [closed])[2022-04-07]
我认为你这样做至少会遇到麻烦,如果你的应用程序“幸存”了审批流程,那可能只是因为审稿人错过了它! 我已经经历了足够的,并且永远不会隐藏任何苹果添加到地图:) ... I think you can at least get into trouble for doing so, if your app "survives" the approval process, it will be probably only because the reviewer missed it! I have already ... -
如果x <50,则忽略,除非x = 100。这将如何完成?(Ignore if x < 50, unless x = 100. How would this be done?)[2023-12-04]
在各种情况下,你不太清楚你想要做什么,所以这里是最通用的代码: if (x == 100) { // do whatever you want to do when x is 100 } else if (x > 50) { // do whatever you want to do when x is (strictly) greater than 50, but not 100 } else { // do whatever you want to do in all other ... -
如果您想在App Store外部发布应用程序,则需要获得iOS Developer Entreprise许可证 (每年299美元)。 您将需要Dun&Bradstreet(DUNS)号码才能注册,并且只能部署到500(注册)设备。 编辑 :另一个选择是要求用户使用某些身份验证(例如用户/通行证)(想想Facebook或Twitter)。 您可以为您的客户提供凭据,以确保只有特定用户才能访问该应用。 If you want to distribute your app outside the App Stor ...
-
100法律如何?(How is 100. legal? [closed])[2023-05-11]
因为语言标准的第6.4.4.2节“浮动常量”因此定义它们: floating-constant: decimal-floating-constant hexadecimal-floating-constant decimal-floating-constant: fractional-constant exponent-part(opt) floating-suffix(opt) digit-sequence exponent-part floating-suffix(op ... -
与数据中任何法律可能性不同的关键[closed](A key distinct from any legal possibilities in the data [closed])[2022-11-17]
sentinel是通常的名字。 http://en.wikipedia.org/wiki/Sentinel_value sentinel is the usual name for this. http://en.wikipedia.org/wiki/Sentinel_value -
是通用基类法律?(Is a Generic Base Class Legal?)[2022-12-26]
是的,您可以从任何类派生,包括一个(或依赖于)模板参数的类。 正如评论中指出的那样,它必须是完整的类型; 也就是说,它必须在实例化模板之前定义。 Yes, you can derive from any class, including one that is (or is dependent on) a template argument. As noted in the comments, it must be a complete type; that is, it must have been de ... -
分割两个整数时,结果将是一个整数。 使其中一个浮动(常数是常数) float percent = grade / 100.0f; When dividing two integers, the result will be an integer. Make one of them a float (the constant is typical) float percent = grade / 100.0f;