标题:Direct2D怎样读取加密jpg?
只看楼主
seahdiao
Rank: 1
来 自:马来西亚
等 级:新手上路
帖 子:20
专家分:0
注 册:2020-3-19
结帖率:100%
 问题点数:0 回复次数:1 
Direct2D怎样读取加密jpg?
比方说,我有一个test.jpg,我把test.jpg的每个字节+=1,然后生成test.dat,请问direct2d应该怎么读取那个test.dat然后用WIC来解码绘制bitmap
搜索更多相关主题的帖子: dat 读取 test jpg 加密 
2021-05-30 16:15
seahdiao
Rank: 1
来 自:马来西亚
等 级:新手上路
帖 子:20
专家分:0
注 册:2020-3-19
得分:0 
找到了,首先先创造一个IWICStream 然后再用InitializeFromMemory来初始化他,最后再用CreateDecoderFromStream来创造Decoder

程序代码:
void dx::loadFromMem() {
    using namespace std;
    fstream file;
    file.open("test.dat", ios::binary | ios::in);

    file.seekp(0, ios::end);
    int length = file.tellp();
    file.seekp(0, ios::beg);
    byte* x = NULL;
    x = new byte[length];
    memset(x, 0, length);
    for (int i = 0; i < length; i++) {
        x[i] = file.get()-1;

    }
    file.close();
    IWICStream* file2=NULL;
    IWICBitmapDecoder* bitmapdecoder = NULL;
    imageFactory->CreateStream(&file2);
    file2->InitializeFromMemory(x, length);
    
    if (S_OK != imageFactory->CreateDecoderFromStream(file2, NULL, WICDecodeMetadataCacheOnLoad, &bitmapdecoder)) {
        MessageBox(NULL, L"Create Decoder Fail", L"cant open 2.jpg", MB_OK);
        exit(-1);
    }


    IWICBitmapFrameDecode* pframe = NULL;
    bitmapdecoder->GetFrame(0, &pframe);

    IWICFormatConverter* fmtcovter = NULL;
    imageFactory->CreateFormatConverter(&fmtcovter);
    fmtcovter->Initialize(pframe, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeCustom);
    renderTarget->CreateBitmapFromWicBitmap(fmtcovter, NULL, &bitmap);

    fmtcovter->Release();
    pframe->Release();
    bitmapdecoder->Release();
}


[此贴子已经被作者于2021-5-31 18:13编辑过]

2021-05-31 18:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505891-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.287573 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved