电子邮件中附加的 9 个 patch png 原始资源不是原始文件
我整个早上都在与一个问题作斗争,我想我现在就在这里问。
我使用以下代码将 9 个补丁图像附加到电子邮件中:
sendIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://com.android9patch.viewer/raw/" + mBaseFilename + String.format("%05d", mAppBackgroundCurrentFile)) );
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, "Email:"));
问题是,当我收到电子邮件时,图像不是原始的 9 个补丁,而是没有比例和填充标记的版本。
我应该得到这个结果:
但我得到的是:
我怀疑应用程序在发送原始文件之前对其进行了处理?
其他信息:
我现在尝试将文件保存到 SDCARD,然后再将其附加到电子邮件中。好吧,出于某种原因,即使复制也会删除比例和填充标记......我不明白。
这是我从原始复制函数获取的复制函数。
private boolean copyToSDCard( int resourceID, String finalName )
{
String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
OutputStream out = null;
try
{
InputStream in = getResources().openRawResource( resourceID );
out = new FileOutputStream(extStorageDirectory + "/" + finalName + ".9.png");
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
catch (Exception e)
{
Log.e("copyToSDCard", e.toString());
e.printStackTrace();
}
return false;
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
I have been fighting with a problem all morning and thought I would ask here now.
I use the following code to attach 9 patch images to an email:
sendIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://com.android9patch.viewer/raw/" + mBaseFilename + String.format("%05d", mAppBackgroundCurrentFile)) );
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, "Email:"));
The problem is that when I get the email, the image is not the original 9 patch, but the version without the scale and padding markers.
I should get this result:
But I get this instead:
I suspect that the app processes the raw file before sending it?
Additional information:
I am now attempting to save the file to the SDCARD before attaching them to the email. Well, for some reason, even copying removes the scale and padding markers... I don't get it.
Here is my copy function I took from raw copy function.
private boolean copyToSDCard( int resourceID, String finalName )
{
String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
OutputStream out = null;
try
{
InputStream in = getResources().openRawResource( resourceID );
out = new FileOutputStream(extStorageDirectory + "/" + finalName + ".9.png");
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
catch (Exception e)
{
Log.e("copyToSDCard", e.toString());
e.printStackTrace();
}
return false;
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终将资产复制到 SD 卡,并使用以下函数将这个新文件附加到电子邮件:
I ended up copying the asset to the sdcard and attaching this new file to the email using the following functions: