Draw與String之間轉換的正確姿勢

2021-09-05 12:04:35 字數 566 閱讀 7676

將draw轉成string,網上有很多類似的**,如下的,但多次互轉的話,draw壓縮很厲害:從一張高畫質圖,到毛玻璃,再到馬賽克,最後消失。基於此,所以寫下此部落格。

網上類似的**:

public drawable bytetodrawable(string icon)   

return null;

}public string drawabletobyte(drawable drawable)

return null;

}

為什麼會被壓縮?

上面**在drawabletobyte中,將drawable轉為bitmap的時候,被壓縮了。在通drawable drawable = new bitmapdrawable(bitmap);未考慮螢幕密度的原因,造成了壓縮。

怎麼解決?

早期的時候,我是在draw轉bitmap的時候做了固定寬高的處理,也是可以實現,但是後面發現,使用新的方式drawable drawable = new bitmapdrawable(getresources(), bitmap);就可以了。

wstring 與 string 之間的轉換

include stdafx.h include common.h include include include std string ws2s const std wstring ws std wstring s2ws const std string s bool bstr to wstrin...

CString與string之間的轉換

嘗試了網上大多數方法,很多都是錯誤的,經過 n次的折騰,終於搞出來了,cstring 是一種很有用的資料型別。它們很大程度上簡化了 mfc中的許多操作,使得 mfc在做字串操作的時候方便了很多。不管怎樣,使用 cstring 有很多特殊的技巧,特別是對於純 c背景下走出來的程式設計師來說有點難以學習...

string 與char char 之間的轉換

1 首先必須了解,string可以被看成是以字元為元素的一種容器。字元構成序列 字串 有時候在字串行中進行遍歷,標準的string類提供了stl容器介面。具有一些成員函式比如begin end 迭代器可以根據他們進行定位。注意,與char 不同的是,string不一定以null 0 結束。strin...