Android 微信分享圖片

private String APP_ID = "00000000000000000"; //微信 APPID
private IWXAPI iwxapi;
private void regToWx() {iwxapi = WXAPIFactory.createWXAPI(context, APP_ID, true);//這里context記得初始化
    iwxapi.registerApp(APP_ID);
}
IMServer.getDiskBitmap(IMServer.url);

這個是我寫的 一個從內存卡讀取照片的類.. ? 可根據自己需求更改

private void wxShare() {Bitmap bp = IMServer.getDiskBitmap(IMServer.url);WXImageObject wxImageObject = new WXImageObject(bp);WXMediaMessage msg = new WXMediaMessage();msg.mediaObject = wxImageObject;//設置縮略圖Bitmap mBp = Bitmap.createScaledBitmap(bp, 120, 120, true);bp.recycle();msg.thumbData = bmpToByteArray(mBp, true);SendMessageToWX.Req req = new SendMessageToWX.Req();req.transaction = buildTransaction("img");//  transaction字段用req.message = msg;req.scene = SendMessageToWX.Req.WXSceneSession;iwxapi.sendReq(req);
}

我先上代碼,我們看看上面的代碼..設置縮略圖那

?

官方給的 代碼是 ?

msg.thumbData?=?Util.bmpToByteArray(thumbBitmap,?true);

然后Util類,居然找不到(我用了qq的jar包,只能在這里找到.....)

所以我只能去demo里面找,然后把bmpToByteArray方法提取出來,如下

public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {ByteArrayOutputStream output = new ByteArrayOutputStream();bmp.compress(Bitmap.CompressFormat.PNG, 100, output);if (needRecycle) {bmp.recycle();}byte[] result = output.toByteArray();try {output.close();} catch (Exception e) {e.printStackTrace();}return result;
}

然后再往下看,

  req.transaction = buildTransaction("img");//  transaction字段用

很明顯 ?后面的是一個方法, 官方也沒給出... ? 老方法 ,去demo里面找,如下

private String buildTransaction(final String type) {return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
}

?

轉載于:https://www.cnblogs.com/zhujiabin/p/7872318.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390780.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390780.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390780.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

蒙蒂霍爾問題_常見的邏輯難題–騎士和刀,蒙蒂·霍爾和就餐哲學家的問題解釋...

蒙蒂霍爾問題While not strictly related to programming, logic puzzles are a good warm up to your next coding session. You may encounter a logic puzzle in your next technical interview as a way to judge your problem solving skills, so its worth being prepare…

西格爾零點猜想_我從埃里克·西格爾學到的東西

西格爾零點猜想I finished reading Eric Siegel’s Predictive Analytics. And I have to say it was an awesome read. How do I define an awesome or great book? A book that changes your attitude permanently. You must not be the same person that you were before y…

C/C++實現刪除字符串的首尾空格

StdStringTrimTest.cpp #include <iostream> int main() {std::string str(" 字符串 String ");std::cout << str << std::endl;std::cout << str.size() << std::endl;str.erase(str.find_first_of( ), str.find_first_not_of…

assign復制對象_JavaScript標準對象:assign,values,hasOwnProperty和getOwnPropertyNames方法介紹...

assign復制對象In JavaScript, the Object data type is used to store key value pairs, and like the Array data type, contain many useful methods. These are some useful methods youll use while working with objects.在JavaScript中&#xff0c; Object數據類型用于存…

HDFS 技術

HDFS定義 Hadoop Distributed File System&#xff0c;是一個使用 Java 實現的、分布式的、可橫向擴展的文件系 統&#xff0c;是 HADOOP 的核心組件 HDFS特點 處理超大文件流式地訪問數據運行于廉價的商用機器集群上&#xff1b; HDFS 不適合以下場合&#xff1a;低延遲數據…

深度學習算法和機器學習算法_啊哈! 4種流行的機器學習算法的片刻

深度學習算法和機器學習算法Most people are either in two camps:大多數人都在兩個營地中&#xff1a; I don’t understand these machine learning algorithms. 我不了解這些機器學習算法。 I understand how the algorithms work, but not why they work. 我理解的算法是如…

Python第一次周考(0402)

2019獨角獸企業重金招聘Python工程師標準>>> 一、單選 1、Python3中下列語句錯誤的有哪些&#xff1f; A s input() B s raw_input() C print(hello world.) D print(hello world.) 2、下面哪個是 Pycharm 在 Windows 下 默認 用于“批量注釋”的快捷鍵 A Ctrl d…

express 路由中間件_Express通過示例進行解釋-安裝,路由,中間件等

express 路由中間件表達 (Express) When it comes to build web applications using Node.js, creating a server can take a lot of time. Over the years Node.js has matured enough due to the support from community. Using Node.js as a backend for web applications a…

ASP.NET 頁面之間傳值的幾種方式

對于任何一個初學者來說&#xff0c;頁面之間傳值可謂是必經之路&#xff0c;卻又是他們的難點。其實&#xff0c;對大部分高手來說&#xff0c;未必不是難點。 回想2016年面試的將近300人中&#xff0c;有實習生&#xff0c;有應屆畢業生&#xff0c;有1-3年經驗的&#xff0c…

Mapreduce原理和YARN

MapReduce定義 MapReduce是一種分布式計算框架&#xff0c;由Google公司2004年首次提出&#xff0c;并貢獻給Apache基金會。 MR版本 MapReduce 1.0&#xff0c;Hadoop早期版本(只支持MR模型)MapReduce 2.0&#xff0c;Hadoop 2.X版本&#xff08;引入了YARN資源調度框架后&a…

數據可視化圖表類型_數據可視化中12種最常見的圖表類型

數據可視化圖表類型In the current era of large amounts of information in the form of numbers available everywhere, it is a difficult task to understand and get insights from these dense piles of data.在當今時代&#xff0c;到處都是數字形式的大量信息&#xff…

三大紀律七項注意(Access數據庫)

三大紀律&#xff08;規則或范式&#xff09; 要有主鍵其他字段依賴主鍵其他字段之間不能依賴七項注意 一表一主鍵(訂單表&#xff1a;訂單號&#xff1b;訂單明細表&#xff1a;訂單號產品編號)經常查&#xff0c;建索引&#xff0c;小數據&#xff08;日期&#xff0c;數字類…

CentOS下安裝JDK的三種方法

來源&#xff1a;Linux社區 作者&#xff1a;spiders http://www.linuxidc.com/Linux/2016-09/134941.htm 由于各Linux開發廠商的不同,因此不同開發廠商的Linux版本操作細節也不一樣,今天就來說一下CentOS下JDK的安裝: 方法一&#xff1a;手動解壓JDK的壓縮包&#xff0c;然后…

MapReduce編程

自定義Mapper類 class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> &#xff5b; … }自定義mapper類都必須實現Mapper類&#xff0c;有4個類型參數&#xff0c;分別是&#xff1a; Object&#xff1a;Input Key Type-------------K1Text: Input…

統計信息在數據庫中的作用_統計在行業中的作用

統計信息在數據庫中的作用數據科學與機器學習 (DATA SCIENCE AND MACHINE LEARNING) Statistics are everywhere, and most industries rely on statistics and statistical thinking to support their business. The interest to grasp on statistics also required to become…

IOS手機關于音樂自動播放問題的解決辦法

2019獨角獸企業重金招聘Python工程師標準>>> 評估手機自帶瀏覽器不能識別 aduio標簽重的autoplay屬性 也不能自動執行play()方法 一個有效的解決方案是在微信jssdk中調用play方法 document.addEventListener("WeixinJSBridgeReady", function () { docum…

svg標簽和svg文件區別_什么是SVG文件? SVG圖片和標簽說明

svg標簽和svg文件區別SVG (SVG) SVG or Scalable Vector Graphics is a web standard for defining vector-based graphics in web pages. Based on XML the SVG standard provides markup to describe paths, shapes, and text within a viewport. The markup can be embedded…

開發人員怎么看實施人員

英文原文&#xff1a;What Developers Think Of Operations&#xff0c;翻譯&#xff1a;張紅月CSDN 在一個公司里面&#xff0c;開發和產品實施對于IS/IT的使用是至關重要的&#xff0c;一個負責產品的研發工作&#xff0c;另外一個負責產品的安裝、調試等工作。但是在開發人員…

怎么評價兩組數據是否接近_接近組數據(組間)

怎么評價兩組數據是否接近接近組數據(組間) (Approaching group data (between-group)) A typical situation regarding solving an experimental question using a data-driven approach involves several groups that differ in (hopefully) one, sometimes more variables.使…

代碼審計之DocCms漏洞分析

0x01 前言 DocCms[音譯&#xff1a;稻殼Cms] &#xff0c;定位于為企業、站長、開發者、網絡公司、VI策劃設計公司、SEO推廣營銷公司、網站初學者等用戶 量身打造的一款全新企業建站、內容管理系統&#xff0c;服務于企業品牌信息化建設&#xff0c;也適應用個人、門戶網站建設…