Android imageview只接受一些jpg
我的应用程序中有一个图像视图。当我尝试让它显示从 3ds max 导出的 jpg 文件时,它起作用了。但如果它来自 Photoshop,它就什么也不做。这是为什么?如果这很重要,我的应用程序使用以下代码从我的服务器获取图像:
public static Bitmap getWebImage(String URL)
{
URL myImageURL = null;
Bitmap bitmap = null;
try {
myImageURL = new URL(URL);
} catch (MalformedURLException error) {
error.printStackTrace();
}
try {
HttpURLConnection connection = (HttpURLConnection)myImageURL .openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
I have an image view in my app. when I try to make it show a jpg file exported from 3ds max, it works. But if it comes from Photoshop, it just does nothing. Why is that? If it is at all important my app gets the image from my server with the following code:
public static Bitmap getWebImage(String URL)
{
URL myImageURL = null;
Bitmap bitmap = null;
try {
myImageURL = new URL(URL);
} catch (MalformedURLException error) {
error.printStackTrace();
}
try {
HttpURLConnection connection = (HttpURLConnection)myImageURL .openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以检查 JPG 文件的颜色设置吗?很可能您的 Photoshop 中的 JPG 文件是 CMYK 而不是 RGB,而 Android 根本不支持 CMYK。
Can you check the color settings of your JPG files? Most likely your JPG files from photoshop is in CMYK rather than RGB, and Android simply doesn't support CMYK.
方便的话可以上传两张图片对比一下吗?
Would it be possible for you to upload the two pictures for comparison?
公共静态位图 getWebImage(字符串 URL)
{
网址 myImageURL = null;
位图 位图 = null;
尝试 {
myImageURL = 新 URL(URL);
} catch (MalformedURLException 错误) {
error.printStackTrace();
}
尝试 {
HttpURLConnection 连接 = (HttpURLConnection)myImageURL .openConnection();
连接.setDoInput(true);
连接.connect();
输入流输入 = 连接.getInputStream();
位图 = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
返回
位图;
}
public static Bitmap getWebImage(String URL)
{
URL myImageURL = null;
Bitmap bitmap = null;
try {
myImageURL = new URL(URL);
} catch (MalformedURLException error) {
error.printStackTrace();
}
try {
HttpURLConnection connection = (HttpURLConnection)myImageURL .openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}