注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[例程]图片圆角化多角化(B4A代码中插入JAVA代码)  

2015-08-17 22:05:57|  分类: B.图形 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
(这个帖子里有多种图片多角化的代码,有兴趣可点上面链接访问)

[例程]图片圆角化多角化(B4A代码中插入JAVA代码) - 沉默蜂 - 沉默蜂B4A安卓编程实战资料
 


#Region  Project Attributes 
#ApplicationLabel: JHSroundBitmap
#VersionCode: 1
#VersionName: 
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim nativeMe As JavaObject

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim bm As Bitmap

Private ImageView1 As ImageView
Private ImageView2 As ImageView
Private ImageView3 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
nativeMe.InitializeContext
bm.Initialize(File.DirAssets,"parrot.jpg")
bm = nativeMe.RunMethod("getRoundBitmap",Array(bm))
ImageView1.Bitmap = bm
ImageView2.Bitmap = bm
ImageView3.Bitmap = bm

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#If Java

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;


public static Bitmap getRoundBitmap(Bitmap scaleBitmapImage) {
int targetWidth = 1000;
int targetHeight = 1000;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(((float) targetWidth - 1) / 2,
((float) targetHeight - 1) / 2,
(Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
Path.Direction.CCW);

canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()), new Rect(0, 0, targetWidth,
targetHeight), null);
return targetBitmap;
}
public static Drawable getRoundDrawable(Drawable d){
Bitmap b=getRoundBitmap(((BitmapDrawable) d).getBitmap());
return new BitmapDrawable(b);
}


#End If


  评论这张
 
阅读(123)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017