当我使用以下代码时,它最终会出现outofmemory异常.做了研究之后,Render脚本看起来像个好人.我在哪里可以找到类似操作的示例代码以及如何将其集成到我的项目中.
public Bitmap rotateBitmap(Bitmap image, int angle) {
if (image != null) {
Matrix matrix = new Matrix();
matrix.postRotate(angle, (image.getWidth()) / 2,
(image.getHeight()) / 2);
return Bitmap.createBitmap(image, 0, 0, image.getWidth(),
image.getHeight(), matrix, true);
}
return null;
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序处于alpha模式但已发布.我可以在开发者控制台中看到这一点"只有alpha和beta测试人员可以在Google Play中看到该列表,因为您还没有将任何APK上传到prod."
但是,当我使用不同的测试帐户测试应用内购买时,我的信用卡被收取了费用.
首先我如何收回我的钱.第二,如何正确测试应用程序,没有收费.
Tharks
这个问题已经讨论了好几次,但是我无法让它发挥作用.我尝试了构建工具v23,甚至没有编译,所以我转移到编译脚本代码的21版本.ScriptC_rotator类现在在app\build\generated\source\rs\debug\com\models中生成.但是,现在我得到运行时'加载ScriptC脚本'.不知道如何解决这个问题.
public Bitmap rotate(Bitmap bitmap) {
Bitmap target = null;
try {
RenderScript rs = RenderScript.create(activity);
ScriptC_rotator script = new ScriptC_rotator(rs); // this is where the error occur.
script.set_inWidth(bitmap.getWidth());
script.set_inHeight(bitmap.getHeight());
Allocation sourceAllocation = Allocation.createFromBitmap(rs, bitmap,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
bitmap.recycle();
script.set_inImage(sourceAllocation);
int targetHeight = bitmap.getWidth();
int targetWidth = bitmap.getHeight();
Bitmap.Config config = bitmap.getConfig();
target = Bitmap.createBitmap(targetWidth, targetHeight, config);
final Allocation targetAllocation = Allocation.createFromBitmap(rs, target,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
script.forEach_rotate_90_clockwise(targetAllocation, targetAllocation);
targetAllocation.copyTo(target);
rs.destroy();
}
catch(Exception e){
}
return target;
}
Run Code Online (Sandbox Code Playgroud)
错误: android.support.v8.renderscript.RSRuntimeException:加载ScriptC脚本失败.
摇篮:
compileSdkVersion 21 …Run Code Online (Sandbox Code Playgroud) 我从图像库中的路径获取文件,并尝试将其加载到图像视图,如下所示.文件路径是:/storage/sdcard0/DCIM/Camera/1436267579864.jpg.我也试过传递Uri我也有读SD卡的权限.
它以onError()方法结束.但是,类似的方法适用于Web网址.我该如何解决这个问题?
private void getImage(File file) {
if(file.exists()) {
Picasso.with(activity)
.load(file)
.error(R.drawable.noimage)
.into(imgPreview, new Callback() {
@Override
public void onSuccess() {
if (progressBar != null && imgPreview != null) {
imgPreview.setVisibility(View.VISIBLE);
imgPreview.setTag("loaded");
progressBar.setVisibility(View.GONE);
}
}
@Override
public void onError() {
if (progressBar != null && imgPreview != null) {
imgPreview.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Run Code Online (Sandbox Code Playgroud) 我想显示3D浮雕外观和感觉,如下图所示.我使用EmbossMaskFilter但无法让它显示效果(请参阅下面的代码).有没有不同的方法来做到这一点?或者我如何使用EmbossMaskFilter.
要求的输出
我的输出
Path path2 = new Path();
public Paint fillPaint = null;
// called in constructor
public void createPath()
{
//path 2 Big one
araay = new Point[]{new Point(144,320),new Point(109,200), new Point(171,308),new Point(178,240),new Point(171,172),new Point(109,282),new Point(144,160)};
AddBeziers(path2, araay, 320, 144);
AddLine(path2, 216, 144 );
AddLine(path2, 216, 216 );
AddLine(path2, 144, 320);
MaskFilter mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
fillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
fillPaint.setColor(Color.WHITE);
fillPaint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
fillPaint.setAntiAlias(true);
fillPaint.setDither(true);
fillPaint.setStrokeJoin(Paint.Join.ROUND);
fillPaint.setStrokeCap(Paint.Cap.ROUND);
fillPaint.setStyle(Paint.Style.FILL);
paint.setMaskFilter(mEmboss); …Run Code Online (Sandbox Code Playgroud) 我有一个游戏视图,它是View类的扩展。在此视图中,我使用画布绘图对象,用户可以与它们进行交互。
此视图已加载到活动的布局。当在布局中单击按钮时,我想禁用所有用户对游戏视图的输入。
我尝试使用
gameView.setEnabled(false);
gameView.setClickable(false);
Run Code Online (Sandbox Code Playgroud)
但是用户仍然可以与画布对象进行交互。
仅供参考:Gameview类也实现以下接口。
public class Gameview extends View implements OnGestureListener,
OnDoubleTapListener, OnScaleGestureListener, AnimationListener
Run Code Online (Sandbox Code Playgroud) 我想为我的应用数据创建一个私人文件夹.从设备中删除应用程序时,必须自动删除此文件夹.根据http://developer.android.com/training/basics/data-storage/files.html,我必须创建一个私人文件夹.我怎样才能做到这一点.我的代码如下.删除应用程序时不会删除文件夹.
public static String getAppFilePath(Context context) {
String path = "";
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
path = Environment.getExternalStorageDirectory()
.getAbsolutePath();
path += "/myFolder";
} else {
ContextWrapper c = new ContextWrapper(context);
path = c.getFilesDir().getPath();
}
File ret = new File(path);
if (!ret.exists()) {
ret.mkdirs();
}
return path;
}
Run Code Online (Sandbox Code Playgroud) 当我使用下面的两种技术计算闭合路径的边界时,我遇到了几个问题。
方法一
public RectF Truncate(Path path) {
RectF figureLocationF = new RectF();
path.computeBounds(figureLocationF, true);
return figureLocationF;
}
Run Code Online (Sandbox Code Playgroud)
方法2
public RectF Truncate(Path path) {
RectF figureLocationF = new RectF();
path.computeBounds(figureLocationF, true);
Rect figureLocation = new Rect((int)Math.floor(figureLocationF.left), (int)Math.floor(figureLocationF.top)
,(int)Math.ceil(figureLocationF.right), (int)Math.ceil(figureLocationF.bottom));
Rect bounds = new Rect();
Region region = new Region();
region.setPath(path, new Region(figureLocation));
region.getBounds(bounds);
return new RectF(bounds)
}
Run Code Online (Sandbox Code Playgroud)
方法 1 返回大于路径的边界,这令人困惑,而方法 2 由于小数舍入而截掉了路径的小部分。
我该如何解决这个问题?有没有办法获得精确的边界。
按下imageview时是否会显示某种效果?我使用imageview作为按钮,因此需要在触摸时显示一些效果.许多现有线程提出具有多个图像的选择器.这是太多的工作,因为我有很多的图像视图.我也愿意扩展imageview类.任何想法或解决方法.
我想在活动和片段以及片段和片段之间传递一个复杂的对象.目前,主活动创建一个片段输入对象,并将其设置为需要打开的片段的成员.类似地,当另一个片段想要加载另一个片段时,它会创建片段输入并通知主要活动.请参阅下面的主要和子片段代码.我的问题是,这是正确的实施.有时我在子活动中遇到输入为null,如果活动暂停并重新启动.
请告诉我我做错了什么,是传递数据的最佳方式.
public class FragmentInput {
public String url = "";
public String title = "";
public String time = "";
... other memebers
}
Run Code Online (Sandbox Code Playgroud)
主要活动
fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
BaseFragment fragment = new LandingFragment();
**FragmentInput input = new FragmentInput();
input.stringinput = stringinput;
fragment.input = input;
fragmentTransaction.replace(R.id.fragment, fragment);
fragmentTransaction.commit();**
public void replaceFragment(BaseFragment fragment) {
if (fragment == null)
return;
if (fragment instanceof firstFragment) {
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.setCustomAnimations(0, 0);
fragmentManager.popBackStackImmediate(null,
FragmentManager.POP_BACK_STACK_INCLUSIVE);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
} …Run Code Online (Sandbox Code Playgroud)