当我实施flood-fill
课程时,它会变成我整个Bitmap
黑色.显然这不是预期的效果.我查看了以下主题:
从我所看到的,我正在做他们在这些解决方案中提出的所有内容,但它并没有让我找到解决问题的方法.所以要切入追逐,这里的代码有一些简短的解释.
XML
我使用相对布局和定位(堆叠)两个ImageViews
直接在彼此之上.它们都具有相同的图像,这就产生了能够在图像上绘制的错觉.但是,您实际上只是在透明覆盖上绘图.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
....
<ImageView
android:id="@+id/drawContainer2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/imageMapperSurfaces"
android:contentDescription="@string/image" />
<ImageView
android:id="@+id/drawContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/imageMapperSurfaces"
android:contentDescription="@string/image" />
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Canvas
然后我Canvas
使用此代码创建我,并确保正确设置我的图层类型.
public void setCanvas() {
if(mFile != null && mFile.exists()) {
mPictureBitmap = BitmapFactory.decodeFile(mFile.getAbsolutePath());
mBitmap = Bitmap.createScaledBitmap(mPictureBitmap, mImageView.getWidth(), mImageView.getHeight(), false);
mPictureBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
mBitmap = mPictureBitmap.copy(Bitmap.Config.ARGB_8888, true);
mSceneBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
mBlurBitmap = blurImage(mPictureBitmap);
mCanvas = new Canvas(mBitmap);
mImageView.setImageBitmap(mBitmap);
mImageView2.setImageBitmap(mPictureBitmap); …
Run Code Online (Sandbox Code Playgroud) 我在最近的一个项目中一直在试验波纹动画.我在寻找一种"优雅"的解决方案时遇到了一些麻烦,在某些情况下使用它来触摸事件.即图像,尤其是列表,网格和循环视图.动画几乎总是看起来在视图后面动画,而不是在它上面.这在Buttons和TextViews中没有问题,但如果您有图像的GridView,则纹波会出现在实际图像的后面或下面.显然这不是我想要的,虽然有些解决方案我认为是一种解决方案,但我希望有一些简单的东西,我只是不知道.
我使用以下代码来实现带有图像的自定义网格视图.我会给出完整的代码点击这里,以便您可以选择.
现在只是重要的东西.为了让我的图像在触摸时动画,我需要这个
button_ripple.xml
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/cream_background">
<item>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Pressed -->
<item
android:drawable="@color/button_selected"
android:state_pressed="true"/>
<!-- Selected -->
<item
android:drawable="@color/button_selected"
android:state_selected="true"/>
<!-- Focus -->
<item
android:drawable="@color/button_selected"
android:state_focused="true"/>
<!-- Default -->
<item android:drawable="@color/transparent"/>
</selector>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
custom_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
android:id="@+id/sceneGridItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_ripple"
android:gravity="center_horizontal"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<GridView
android:id="@+id/sceneGrid"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:verticalSpacing="15dp"
android:numColumns="5" />
Run Code Online (Sandbox Code Playgroud)
所有魔术和问题发生的线都是我设置背景的时候.虽然这实际上在我的imageview上给我一个波纹动画,但它在imageview 背后动画.我希望动画显示在图像的顶部.所以我尝试了一些不同的东西
将整个网格背景设置为button_ripple.
<GridView
android:id="@+id/sceneGrid"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:verticalSpacing="15dp"
android:background="@drawable/button_ripple"
android:numColumns="5" …
Run Code Online (Sandbox Code Playgroud) 我有一个带有背景图像的画布。我需要知道是否有可能清除此画布上的涂料以重绘而不清除其背景图像。这是我的示例以及到目前为止的结果。
爪哇
public void setCanvas() {
if(mFile != null && mFile.exists()) {
mPictureBitmap = BitmapFactory.decodeFile(mFile.getAbsolutePath());
mBitmap = Bitmap.createScaledBitmap(mPictureBitmap, mImageView.getWidth(), mImageView.getHeight(), false);
mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
mCanvas = new Canvas(mBitmap);
mImageView.setImageBitmap(mBitmap);
mImageView.setOnTouchListener(this);
}
}
private void draw() {
mCanvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); // THIS LINE CLEARS
int lastIndex = mCordHashMap.size() - 1;
int index = 0;
for (LinkedHashMap.Entry<String, ArrayList<Circle>> entry : mCordHashMap.entrySet()) {
ArrayList<Circle> coords = new ArrayList<Circle>();
coords = entry.getValue();
Path path = new Path();
String key = entry.getKey();
String surface = …
Run Code Online (Sandbox Code Playgroud)