zoukankan      html  css  js  c++  java
  • cximage 裁剪图片并背景透明

    extern "C" _declspec(dllexport) bool __stdcall SaveImage2(const char* srcImage, const char* json, bool transparent)
    {
        CxImage image;
        if (!image.Load(srcImage, CXIMAGE_FORMAT_TIF))
            return false;
    
        neb::CJsonObject oJson(json);
    
        int count = oJson.GetArraySize();
        for (int i = 0; i < count; i++)
        {
            int left, top, width, height;
            string path;
            oJson[i]["Region"].Get("Left", left);
            oJson[i]["Region"].Get("Top", top);
            oJson[i]["Region"].Get("Width", width);
            oJson[i]["Region"].Get("Height", height);
            oJson[i].Get("Path", path);
    
            int imageWidth = image.GetWidth();
            if (width > imageWidth - left)
                width = imageWidth - left;
    
            int imageHeight = image.GetHeight();
            if (height > imageHeight - top)
                height = imageHeight - top;
    
            CxImage subImage(imageWidth, imageHeight);
            
            RECT r;
            r.left = left;
            r.right = left + width;
            r.top = top;
            r.bottom = top + height;
    
            if (!image.Crop(r, &subImage))
                return false;
    
            if (transparent)
            {
                if (subImage.GetTransIndex() != 24)
                {
                    subImage.IncreaseBpp(24);
                }
                subImage.SetTransIndex(0);
                int B = 255, G = 255, R = 255;
                RGBQUAD rgbTrans = { B, G, R, 0 };
                subImage.SetTransColor(rgbTrans);
            }
    
            if (!subImage.Save(path.c_str(), CXIMAGE_FORMAT_GIF))
                return false;
        }
    
        return true;
    }
    桂棹兮兰桨,击空明兮溯流光。
  • 相关阅读:
    人类思考的基本形式
    晚上睡不者原因
    东西方哲学比较
    逻辑推理的三种方法
    锻炼自己的注意力和逻辑思维能力
    预测和复盘自己的投资策略
    概念:名与实
    没有“界定问题”会出现什么问题
    问题、联系-条条大路通罗马
    程序问题调试与医生、汽车维修师
  • 原文地址:https://www.cnblogs.com/nanfei/p/14340681.html
Copyright © 2011-2022 走看看