我从Facebook获取图像并将其写入SD卡,但图像质量很低。以下是我的代码来读取和写入:从Facebook获取并写入SD的图像质量非常低。
try
{
URL url = new URL(murl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
data1 = String.valueOf(String.format(getActivity().getApplicationContext().getFilesDir()+"/Rem/%d.jpg",System.currentTimeMillis()));
FileOutputStream stream = new FileOutputStream(data1);
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
byte[] byteArray = outstream.toByteArray();
stream.write(byteArray);
stream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
下面的代码我用来显示相同的图像:即使使用选项后
File IMG_FILE = new File(IMAGE_CONTENT);
B2.setVisibility(View.INVISIBLE);
Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(IMG_FILE.getAbsolutePath(),options);
iM.setImageBitmap(bitmap);
质量仍然较低。可以做些什么来改善这一点?
我的要求是保存它,因为我的列表中的一些其他图像是从内存中显示的,并且在网络和内存之间交换会使我的列表无效。 – Skynet
使用上面的代码将图像保存到SD卡从web url.in上面的代码中,您将图像保存为原始byte.so,您的图像质量将不会降低。 – Ruban
我在上面,谢谢队友:) – Skynet