本文整理汇总了Java中com.tencent.mm.sdk.modelmsg.WXImageObject类的典型用法代码示例。如果您正苦于以下问题:Java WXImageObject类的具体用法?Java WXImageObject怎么用?Java WXImageObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WXImageObject类属于com.tencent.mm.sdk.modelmsg包,在下文中一共展示了WXImageObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendImage
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private void sendImage() {
switch (instance.api) {
case QQ:
String appName = mContext.getString(R.string.app_name);
Bundle params = QQUtils.genImgMsg(appName, title, description, qqTagetUrl, qqImgUrl, qqFilePath);
configInstance.getTencentApi().shareToQQ((Activity) mContext, params, new QQCallbackListener());
return;
case WeChat:
WXImageObject imgObj = new WXImageObject();
Bitmap thumbBmp = Bitmap.createScaledBitmap(wxImgBmp, THUMB_SIZE, THUMB_SIZE, true);
wxImgBmp.recycle();
WXMediaMessage msg = WxUtils.genMsg(imgObj, title, description, thumbBmp);
// 调用api接口发送数据到微信
configInstance.getWxApi().sendReq(WxUtils.genRequest(msg, instance.type));
return;
case SinaWeiBo:
return;
}
}
示例2: shareToWechat
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private static void shareToWechat(String transaction, Activity activity, String title, String summary, Bitmap img, int flag) {
IWXAPI wxApi = getWxApi();
WXImageObject imgObj = new WXImageObject(img);
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
//Bitmap thumbBmp = Bitmap.createScaledBitmap(img, THUMB_SIZE, THUMB_SIZE, true);
msg.thumbData = bmpToThumbArray(img);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = transaction;
req.message = msg;
req.scene = flag;
wxApi.sendReq(req);
}
示例3: sharePicture
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private void sharePicture(int shareType, Message.Picture message) {
Bitmap bitmap = message.getImage();
Bitmap thumbImage = Bitmap.createScaledBitmap(bitmap, THUMB_SIZE, THUMB_SIZE, false);
WXImageObject imgObj = new WXImageObject(bitmap);
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
if (thumbImage != null) {
msg.setThumbImage(thumbImage);
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = ShareUtil.buildTransaction("imgshareappdata");
req.message = msg;
req.scene = shareType;
mIWXAPI.sendReq(req);
}
示例4: sendImage
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private void sendImage(int type, Bitmap bitmap) {
Bitmap thumb = getThumbBitmap(bitmap);
WXImageObject imageObject = new WXImageObject(bitmap);
WXMediaMessage msg = new WXMediaMessage(imageObject);
msg.title = mShareOption.title;
msg.description = mShareOption.description;
msg.thumbData = Utils.bmpToByteArray(thumb, true);
SendMessageToWX.Req request = new SendMessageToWX.Req();
request.transaction = "image" + System.currentTimeMillis();
request.message = msg;
request.scene = type;
mWXAPI.sendReq(request);
}
示例5: test
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private void test() {
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
WXImageObject imgObj = new WXImageObject(bmp);
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 200, 200, true);
bmp.recycle();
msg.thumbData = BitmapUtils.bmpToByteArray(thumbBmp, true); //
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = System.currentTimeMillis() + "";
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneSession;
api.sendReq(req);
}
示例6: shareImageByPath
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
/***
* @param path the local image path
*/
public void shareImageByPath(String path,String title ,String desc,boolean shareToFriendCircle,IWXShareCallback callback){
WXImageObject imgObj = new WXImageObject();
imgObj.setImagePath(path);
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
msg.title = title;
msg.description = desc;
// Bitmap bmp = BitmapFactory.decodeFile(path);
Bitmap bmp = new ImageParser(0,0).parseToBitmap(path);
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
bmp.recycle();
msg.thumbData = Util.bitampToByteArray(thumbBmp);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("img");
req.message = msg;
req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
mCallbackMap.put(req.transaction.hashCode(),callback);
mWxApi.sendReq(req);
}
示例7: share
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
@Override
public void share(Activity activity, Bitmap shareBitmap, Bitmap thumbBitmap, int platform) {
ShareType = ShareConstant.SHARE;
this.platform = platform;
if (activity == null)
return;
thumbBitmap = GlideBitmapFactory.decodeFile(savePath);
if (api == null) {
api = WXAPIFactory.createWXAPI(activity, BuildConfig.WECHAT_APP_ID, false);
api.registerApp(BuildConfig.WECHAT_APP_ID);
}
WXMediaMessage msg = new WXMediaMessage();
msg.thumbData = Util.bmpToByteArray(thumbBitmap, true);
WXImageObject imgObj = new WXImageObject();
imgObj.setImagePath(savePath);
msg.mediaObject = imgObj;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = "img" + System.currentTimeMillis();
req.message = msg;
if (platform == ShareConstant.SHARE_MEDIA.WECHAT) {
req.scene = SendMessageToWX.Req.WXSceneSession;
} else if (platform == ShareConstant.SHARE_MEDIA.WECHAT_CIRCLE) {
req.scene = SendMessageToWX.Req.WXSceneTimeline;
}
api.sendReq(req);
if (thumbBitmap != null) {
thumbBitmap.recycle();
}
}
示例8: buildImageParams
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private WXMediaMessage buildImageParams() {
parseImage(this.mShareMedia);
WXImageObject imgObj = new WXImageObject();
WXMediaMessage msg = buildMediaMessage();
if (TextUtils.isEmpty((CharSequence) this.mExtraData.get("image_path_local"))) {
imgObj.imageUrl = (String) this.mExtraData.get("image_path_url");
} else {
imgObj.imagePath = (String) this.mExtraData.get("image_path_local");
}
msg.mediaObject = imgObj;
return msg;
}
示例9: shareImage
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
public static boolean shareImage(Bitmap image, String title, String desc, Bitmap thumb, int scene) {
if (!isAppInstalled())
return false;
WXImageObject imgObj = new WXImageObject();
imgObj.imageData = BitmapHelper.compressJPEG(image, 80);
return shareObject(imgObj, title, desc, thumb, scene);
}
示例10: sharePic
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private void sharePic(Bitmap bmp, Bitmap thumbBmp, boolean isTimeline) {
WXImageObject imgObj = new WXImageObject();
imgObj.imageData = bmpToBytes(bmp);
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
// 缩略图
if (thumbBmp != null) {
msg.thumbData = bmpToBytes(thumbBmp);
} else if (bmp != null) {
Bitmap thumb = ShareWechatUtils.extractThumbNail(bmp, THUMB_SIZE, THUMB_SIZE, true);
if (thumb != null) {
Logger.e("Share:", "图片不为null");
}
// msg.setThumbImage(thumb);
msg.thumbData = bmpToBytes(thumb);
}
// 构造一个Req
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = ShareWechatUtils.buildTransaction("img");
req.message = msg;
req.scene = isTimeline ? SendMessageToWX.Req.WXSceneTimeline
: SendMessageToWX.Req.WXSceneSession;
mAPI.sendReq(req);
}
示例11: createMediaObject
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
@Override
protected WXMediaMessage.IMediaObject createMediaObject() {
WXImageObject object = new WXImageObject();
switch (getShareParams().getImage().getSource()) {
case File:
object.imagePath = getShareParams().getImage().getImageFile().getPath();
break;
case Bitmap:
case Http:
object.imageData = ShareImageUtils.getCompressData(getShareParams().getImage(), MAX_IMAGE_SIZE);
thumbData = object.imageData;
break;
}
return object;
}
示例12: doInBackground
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
@Override
protected SendMessageToWX.Req doInBackground(Object... params) {
final String url = (String) params[0];
final String title = (String)params[1];
final String desc = (String)params[2];
final boolean shareToFriendCircle = (Boolean)params[3];
final IWXShareCallback callback = (IWXShareCallback)params[4];
WXImageObject imgObj = new WXImageObject();
imgObj.imageUrl = url;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
msg.title = title;
msg.description = desc;
final String transaction = buildTransaction("img");
mCallbackMap.put(transaction.hashCode(), callback);
try {
Bitmap bmp = new ImageParser(0,0).parseToBitmap(IoUtil.getBytesFromStreamAndClose(
new URL(url).openStream()));
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
bmp.recycle();
msg.thumbData = Util.bitampToByteArray(thumbBmp);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = transaction;
req.message = msg;
req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline
: SendMessageToWX.Req.WXSceneSession;
return req ;
} catch (IOException e) {
e.printStackTrace();
}
SendMessageToWX.Req req2 = new SendMessageToWX.Req();
req2.transaction = transaction;
req2.message = null;
return req2;
}
示例13: a
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
private boolean a(String s1, boolean flag)
{
if (!t.isWXAppInstalled())
{
CustomToast.makeText(this, 0x7f0d017d, 0).show();
return false;
}
WXImageObject wximageobject = new WXImageObject();
wximageobject.setImagePath(s1);
android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory.Options();
options.inSampleSize = 4;
M = BitmapFactory.decodeFile(s1, options);
WXMediaMessage wxmediamessage = new WXMediaMessage();
wxmediamessage.mediaObject = wximageobject;
wxmediamessage.title = v;
wxmediamessage.description = w;
if (M != null)
{
wxmediamessage.setThumbImage(M);
}
com.tencent.mm.sdk.modelmsg.SendMessageToWX.Req req = new com.tencent.mm.sdk.modelmsg.SendMessageToWX.Req();
req.transaction = String.valueOf(System.currentTimeMillis());
req.message = wxmediamessage;
int i1 = 0;
if (flag)
{
i1 = 1;
}
req.scene = i1;
return t.sendReq(req);
}
示例14: shareImage
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
@Override
public void shareImage(final int platform, final ShareImageObject shareImageObject,
final Activity activity, final ShareListener listener) {
Observable.fromEmitter(new Action1<Emitter<Pair<Bitmap, byte[]>>>() {
@Override
public void call(Emitter<Pair<Bitmap, byte[]>> emitter) {
try {
String imagePath = ImageDecoder.decode(activity, shareImageObject);
emitter.onNext(Pair.create(BitmapFactory.decodeFile(imagePath),
ImageDecoder.compress2Byte(imagePath, TARGET_SIZE, THUMB_SIZE)));
} catch (Exception e) {
emitter.onError(e);
}
}
}, Emitter.BackpressureMode.BUFFER)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnRequest(new Action1<Long>() {
@Override
public void call(Long aLong) {
listener.shareRequest();
}
})
.subscribe(new Action1<Pair<Bitmap, byte[]>>() {
@Override
public void call(Pair<Bitmap, byte[]> pair) {
WXImageObject imageObject = new WXImageObject(pair.first);
WXMediaMessage message = new WXMediaMessage();
message.mediaObject = imageObject;
message.thumbData = pair.second;
sendMessage(platform, message, buildTransaction("image"));
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
activity.finish();
listener.shareFailure(new Exception(throwable));
}
});
}
示例15: shareImg
import com.tencent.mm.sdk.modelmsg.WXImageObject; //导入依赖的package包/类
public void shareImg(Bitmap bitmap, OnShareListener listener) {
if (null == bitmap) {
if (null != listener) {
listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
}
return;
}
if (api.isWXAppInstalled()) {
if (api.isWXAppSupportAPI()) {
WXMediaMessage wxMediaMessage = new WXMediaMessage();
wxMediaMessage.mediaObject = new WXImageObject(bitmap);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
while (width * height > THUMB_SIZE * THUMB_SIZE) {
width /= 2;
height /= 2;
}
Bitmap thumbBmp = Bitmap.createScaledBitmap(bitmap, width, height, true);
try {
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
thumbBmp.compress(Bitmap.CompressFormat.JPEG, 85, localByteArrayOutputStream);
wxMediaMessage.thumbData = localByteArrayOutputStream.toByteArray();
localByteArrayOutputStream.close();
} catch (Exception e) {
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = String.valueOf(System.currentTimeMillis());
req.message = wxMediaMessage;
if (ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND == channel) {
req.scene = SendMessageToWX.Req.WXSceneSession;
} else if (ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE == channel) {
req.scene = SendMessageToWX.Req.WXSceneTimeline;
}
api.sendReq(req);
}
} else {
if (null != listener) {
listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
}
ToastUtil.showToast(context, R.string.share_no_weixin_client, true);
}
}