UE4 将本地图片转成UTexture2D 在runtime显示

UFUNCTION(BlueprintCallable, Category = "TextureFromDisk")
        static class UTexture2D* GetTexture2DFromDiskFile(const FString& FilePath);
class UTexture2D* UTextureFromDiskFunctionLibrary::GetTexture2DFromDiskFile(const FString& FilePath)
{
    TArray<uint8> RawFileData;
    UTexture2D* MyTexture = NULL;
    if (FFileHelper::LoadFileToArray(RawFileData, *FilePath /*"<path to file>"*/))
    {
        IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
        // Note: PNG format.  Other formats are supported
        IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
        if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
        {
            const TArray<uint8>* UncompressedBGRA = NULL;
            if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
            {
                // Create the UTexture for rendering
                MyTexture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);

                // Fill in the source data from the file
                void* TextureData = MyTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
                FMemory::Memcpy(TextureData, UncompressedBGRA->GetData(), UncompressedBGRA->Num());
                MyTexture->PlatformData->Mips[0].BulkData.Unlock();

                // Update the rendering resource from data.
                MyTexture->UpdateResource();
            }
        }
    }
    return MyTexture;
}

别忘记头文件的引用

#include "Developer/ImageWrapper/Public/Interfaces/IImageWrapper.h"
#include "Developer/ImageWrapper/Public/Interfaces/IImageWrapperModule.h"
时间: 2024-08-06 03:38:51

UE4 将本地图片转成UTexture2D 在runtime显示的相关文章

C#将image中的显示的图片转换成二进制

原文:C#将image中的显示的图片转换成二进制 1.将Image图像文件存入到数据库中 我们知道数据库里的Image类型的数据是"二进制数据",因此必须将图像文件转换成字节数组才能存入数据库中. //将本地图片转换成二进制保存起来 private byte[] SetImageToByteArray(string fileName) { FileStream fs = null; try { fs = new FileStream(fileName, FileMode.Open, S

在InternetExplorer.Application中显示本地图片

忘记了,喜欢一个人的感觉 Demon's Blog  ?  程序设计  ?  在InternetExplorer.Application中显示本地图片 ? 对VBS效率的再思考--处理二进制数据 WordPress判断用户是否登录 ? 在InternetExplorer.Application中显示本地图片 标题: 在InternetExplorer.Application中显示本地图片作者: Demon链接: http://demon.tw/programming/internetexplor

android项目中的拍照和本地图片截图

1,得到保存截图文件的地址 private static final String IMAGE_FILE_LOCATION = Environment.getExternalStorageDirectory()+"/temp.jpg"; private Uri imageUri; imageUri = Uri.fromFile(new File(IMAGE_FILE_LOCATION)); 2.相冊和拍照button的点击事件 // 相冊 imageViewLocalPhoto.set

微信小程序使用本地图片在真机不显示的问题

最近做的小程序,在真机测试发现有些本地图片在开发工具上可以显示,但是在真机上预览的时候不能显示 代码是这样写的 <view class='seat-size' wx:for="{{item}}" wx:key="index" wx:for-index="index" wx:for-item="citem"> <image src='../../../images/seaticon.png' class='se

通过拍照或选择本地图片并剪裁图片设置成头像,并保存裁剪后图片与本地方便注册头像上传

1 import java.io.File; 2 3 import android.app.AlertDialog; 4 import android.content.Context; 5 import android.content.DialogInterface; 6 import android.content.Intent; 7 import android.graphics.Bitmap; 8 import android.graphics.drawable.BitmapDrawabl

将图片转成base64写进hml,无需依赖本地文件

因项目需求更改,本来html中的图片是需要本地图片支持的,结果改了  经过自己查阅资料,轻松搞定 1,通过base64encodee.encode(byte[]) ,将文件的字节数组传入,得到一个字符串  str, 2,标签<img  src=""/ >,   将 字符串 """data:image/jpeg;base64," 放到str 前面 例子:<img src='data:image/jpeg;base64,iVBORw

UIWebView显示本地图片的方法

在UIWebView显示本地图片,由此可借助UIWebView实现图文混排(内容编码成html格式即可). // ViewController.m // // Created by zc on 8/1/14. // Copyright (c) 2014 cuibo. All rights reserved. // #import "ViewController.h" @interface ViewController () <UIWebViewDelegate> @prop

dedecms织梦添加ueditor百度编辑器(支持本地图片水印)

本站所有附件均为UTF-8版本,GBK版本的童学请自行转码: 教程最下面有解决栏目内容添加失败的解决方法和本地上传图片加水印方法. 最终效果 1.直接到百度编辑器官方下载PHP对应的版本 ueditor官方地址:http://ueditor.baidu.com/website/download.html 2.dedecms 程序 include文件夹下,创建 ueditor 文件夹 把下载到的ueditor文件扔进去(index.html不要) 3.include\inc\inc_fun_fun

Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

首先我们先看第一个界面吧,使用将手机中的图片扫描出来,然后根据图片的所在的文件夹将其分类出来,并显示所在文件夹里面的一张图片和文件夹中图片个数,我们根据界面元素(文件夹名, 文件夹图片个数,文件夹中的一张图片)使用一个实体对象ImageBean来封装这三个属性 package com.example.imagescan; /** * GridView的每个item的数据对象 * * @author len * */ public class ImageBean{ /** * 文件夹的第一张图片路