日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Skia最新“编译”,绘制中文字符串,加载PNG、BMP图片等资料的整理。

發布時間:2024/3/26 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Skia最新“编译”,绘制中文字符串,加载PNG、BMP图片等资料的整理。 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

“編譯”Skia

國內不適合自己編譯。Github 有不止一個自動構建的SKIA二進制build,涵蓋多個操作系統,可直接取而用之。

推薦大名鼎鼎的JetBrains維護的倉庫,地址是 https://github.com/JetBrains/skia-build。含靜態庫與頭文件。release靜態庫解壓出來180MB,debug解壓出來一兩個G。推薦直接用release版本的。

繪制中文字符串

直接用Skia的SkString就可以,無需多次轉換。如果顯示方框,那說明字體不對,要設置宋體。

auto pFace = SkTypeface::MakeFromName("宋體", SkFontStyle::Normal()); SkFont font; font.setTypeface(pFace);SkString string("加載圖片 #");canvas->drawString(string, 1, 28, font, textpaint);

完整代碼見文末的demo

加載并顯示PNG圖片等

百度“Skia繪制圖片”出來的結果大多已經過時。

最新方法,要用 SkCodec::MakeFromData 解析二進制流,得到SkCodec 與 SkImageInfo,中SkImageInfo包括圖片尺寸信息,然后再解碼為 SkBitmap。

DWORD fileLength;char* memFile;... 加載文件到 memFile數組中sk_sp<SkData> data = SkData::MakeWithoutCopy(memFile, fileLength);auto codec = SkCodec::MakeFromData(data);if (!codec) {LogIs(2, "FAILED DECODING FILE!");}SkImageInfo codecInfo = codec->getInfo();auto alphaType = codecInfo.isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;auto decodeInfo = SkImageInfo::Make(codecInfo.width(), codecInfo.height(), kN32_SkColorType, alphaType);SkBitmap* skBitmap = new SkBitmap();char* pixels = new char[codecInfo.width()*codecInfo.height()*32];skBitmap->setInfo(decodeInfo, codecInfo.width()*32);skBitmap->setPixels(pixels);auto decodeResult = codec->getPixels(decodeInfo, pixels, codecInfo.width()*32);

decodeResult 等于零代表成功,其他可能的數值:

/*** Error codes for various SkCodec methods.*/enum Result {/*** General return value for success.*/kSuccess, 0/*** The input is incomplete. A partial image was generated.*/kIncompleteInput, 1/*** Like kIncompleteInput, except the input had an error.** If returned from an incremental decode, decoding cannot continue,* even with more data.*/kErrorInInput, 2/*** The generator cannot convert to match the request, ignoring* dimensions.*/kInvalidConversion, 3/*** The generator cannot scale to requested size.*/kInvalidScale, 4/*** Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes* too small, etc.*/kInvalidParameters, 5/*** The input did not contain a valid image.*/kInvalidInput, 6/*** Fulfilling this request requires rewinding the input, which is not* supported for this input.*/kCouldNotRewind, 7/*** An internal error, such as OOM.*/kInternalError, 8/*** This method is not implemented by this codec.* FIXME: Perhaps this should be kUnsupported?*/kUnimplemented, 9};

完整 Demo 代碼 | 我的Skia測試盒子

運行:

參考資料:《調用Skia內置位圖編解碼器的坑點》

總結

以上是生活随笔為你收集整理的Skia最新“编译”,绘制中文字符串,加载PNG、BMP图片等资料的整理。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。