电子邮件中附加的 9 个 patch png 原始资源不是原始文件

发布于 2025-01-08 12:11:58 字数 1818 浏览 2 评论 0原文

我整个早上都在与一个问题作斗争,我想我现在就在这里问。

我使用以下代码将 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 个补丁,而是没有比例和填充标记的版本。

我应该得到这个结果: 预期结果附件

但我得到的是: Result returned

我怀疑应用程序在发送原始文件之前对其进行了处理?

其他信息

我现在尝试将文件保存到 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:
Expected result attachment

But I get this instead:
Result received

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ懵逼小萝莉 2025-01-15 12:11:58

我最终将资产复制到 SD 卡,并使用以下函数将这个新文件附加到电子邮件:

...
if( copyAssetToSDCard( filename, basepath + filename ) )
{
    uris.add( Uri.parse( "file://" + basepath + filename ) );
}
...


private boolean copyAssetToSDCard( String SrcFilename, String DstFilename )
{
    OutputStream out = null;

    try
    {
        AssetManager assetManager = getResources().getAssets();
        InputStream in = assetManager.open(SrcFilename);
        out = new FileOutputStream(DstFilename);
        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;

        return true;
    }
    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 ended up copying the asset to the sdcard and attaching this new file to the email using the following functions:

...
if( copyAssetToSDCard( filename, basepath + filename ) )
{
    uris.add( Uri.parse( "file://" + basepath + filename ) );
}
...


private boolean copyAssetToSDCard( String SrcFilename, String DstFilename )
{
    OutputStream out = null;

    try
    {
        AssetManager assetManager = getResources().getAssets();
        InputStream in = assetManager.open(SrcFilename);
        out = new FileOutputStream(DstFilename);
        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;

        return true;
    }
    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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文