package com.spacesoftwares.imageeditv01;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView mImgView;
private ImageView mDstImg;
private Button mBtn1, mBtn2, mBtn3, mBtn4;
private Bitmap mBitmap1, mBitmap2, mBitmap3, mBitmap4, mBitmap5;
int wd = 100;
int ht = 100;
int[] pixels;
public final int BLACK = -16777216; // (0xff000000)
public final int BLUE = -16776961; // (0xff0000ff)
public final int CYAN = -16711681; // (0xff00ffff)
public final int DKGRAY = -12303292; // (0xff444444)
public final int GRAY = -7829368; // (0xff888888)
public final int GREEN = -16711936; // (0xff00ff00)
public final int LTGRAY = -3355444; // (0xffcccccc)
public final int MAGENTA = -65281; // (0xffff00ff)
public final int RED = -65536; // (0xffff0000)
public final int TRANSPARENT = 0; // (0x00000000)
public final int WHITE = -1; // (0xffffffff)
public final int YELLOW = -256; // (0xffffff00)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_view);
// Load bitmap1
// options is to ensure getting the original size, i.e., no magnification or shrink when reading into memory
// otherwise getWidth and getHeight will give different dimension depending on your display device
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
mBitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.r100, opts);
wd = mBitmap1.getWidth();
ht = mBitmap1.getHeight();
mImgView = findViewById(R.id.id_image);
mImgView.setScaleType(ImageView.ScaleType.CENTER);
//mImgView.setImageResource(R.drawable.r100);
mImgView.setImageBitmap(mBitmap1);
mDstImg = findViewById(R.id.id_dst_image);
//mDstImg.setScaleType(ImageView.ScaleType.CENTER);
//mDstImg.setImageResource(R.drawable.r100);
mDstImg.setImageBitmap(mBitmap1);
mBtn1 = findViewById(R.id.id_btn1);
mBtn2 = findViewById(R.id.id_btn2);
mBtn3 = findViewById(R.id.id_btn3);
mBtn4 = findViewById(R.id.id_btn4);
setListeners();
pixels = new int[2*wd*ht];
for(int i=0; i<2*wd*ht; i++){
pixels[i] = YELLOW;
}
}
private void setListeners(){
OnClick onClick = new OnClick();
mBtn1.setOnClickListener(onClick);
mBtn2.setOnClickListener(onClick);
mBtn3.setOnClickListener(onClick);
mBtn4.setOnClickListener(onClick);
}
private class OnClick implements View.OnClickListener {
int offset = 0;
public void onClick(View v){
switch(v.getId()){
case R.id.id_btn1:
//mDstImg.setImageDrawable(null);
mBitmap1.getPixels(pixels, 0, 2*wd, 0, 0, wd, ht);
mBitmap1.getPixels(pixels, wd, 2*wd, 0, 0, wd, ht);
mBitmap2 = Bitmap.createBitmap(pixels, 0, 2*wd, 2*wd, ht, Bitmap.Config.ARGB_8888);
mDstImg.setImageBitmap(mBitmap2);
mImgView.setImageBitmap(mBitmap1);
break;
case R.id.id_btn2:
offset = (2*wd)*(ht/2)+wd/2;
mBitmap1.getPixels(pixels, offset, 2*wd-1, wd/2, ht/2, wd/2, ht/2);
mBitmap3 = Bitmap.createBitmap(pixels, 0, 2*wd, 2*wd, ht, Bitmap.Config.ARGB_8888);
mDstImg.setImageBitmap(mBitmap3);
break;
case R.id.id_btn3:
mDstImg.setImageDrawable(null);
offset = (2*wd)*(ht/2)+wd/2;
mBitmap1.getPixels(pixels, offset, 2*wd, wd/2, ht/2, wd/2, ht/2);
mBitmap1.getPixels(pixels, offset+wd, 2*wd, wd/2, ht/2, wd/2, ht/2);
mBitmap4 = Bitmap.createBitmap(pixels, 0, 2*wd, 2*wd, ht, Bitmap.Config.ARGB_8888);
mDstImg.setImageBitmap(mBitmap4);
break;
case R.id.id_btn4:
mDstImg.setImageDrawable(null);
offset = (2*wd)*(ht/2);
mBitmap1.getPixels(pixels, offset, 2*wd, wd/2, ht/2, wd/2, ht/2);
mBitmap1.getPixels(pixels, offset+wd, 2*wd, wd/2, ht/2, wd/2, ht/2);
mBitmap5 = Bitmap.createBitmap(pixels, 0, 2*wd, 2*wd, ht, Bitmap.Config.ARGB_8888);
mDstImg.setImageBitmap(mBitmap5);
break;
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
收起资源包目录
ImageEditV01.zip (80个子文件)
.gitignore 147B
app
.gitignore 8B
build.gradle 996B
src
androidTest
java
com
spacesoftwares
imageeditv01
ExampleInstrumentedTest.java 772B
main
AndroidManifest.xml 745B
res
mipmap-xhdpi
ic_launcher_round.png 7KB
ic_launcher.png 4KB
mipmap-mdpi
ic_launcher_round.png 3KB
ic_launcher.png 2KB
layout
image_view.xml 2KB
activity_main.xml 785B
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 6KB
drawable
r100.png 420B
r200.png 687B
ic_launcher_background.xml 6KB
mipmap-anydpi-v26
ic_launcher_round.xml 276B
ic_launcher.xml 276B
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-hdpi
ic_launcher_round.png 5KB
ic_launcher.png 3KB
mipmap-xxxhdpi
ic_launcher_round.png 15KB
ic_launcher.png 9KB
values
strings.xml 78B
colors.xml 214B
styles.xml 399B
java
com
spacesoftwares
imageeditv01
MainActivity.java 5KB
test
java
com
spacesoftwares
imageeditv01
ExampleUnitTest.java 408B
build
libs
proguard-rules.pro 772B
app.iml 12KB
settings.gradle 16B
build.gradle 573B
gradlew 5KB
gradlew.bat 2KB
gradle.properties 739B
.gradle
4.4
javaCompile
javaCompile.lock 17B
fileContent
fileContent.lock 17B
fileHashes
fileHashes.lock 17B
taskHistory
taskHistory.lock 17B
fileChanges
buildOutputCleanup
buildOutputCleanup.lock 17B
cache.properties 51B
.idea
misc.xml 2KB
libraries
Gradle__com_android_support_test_espresso_espresso_core_3_0_2.xml 718B
Gradle__android_arch_lifecycle_livedata_core_1_1_0.xml 696B
Gradle__com_android_support_support_core_ui_27_1_1.xml 705B
Gradle__net_sf_kxml_kxml2_2_3_0_jar.xml 518B
Gradle__android_arch_lifecycle_common_1_1_0_jar.xml 555B
Gradle__com_android_support_constraint_constraint_layout_solver_1_1_2_jar.xml 433B
Gradle__com_android_support_support_annotations_27_1_1_jar.xml 617B
Gradle__com_android_support_support_core_utils_27_1_1.xml 720B
Gradle__com_squareup_javawriter_2_1_1_jar.xml 546B
Gradle__com_android_support_support_compat_27_1_1.xml 700B
Gradle__com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml 773B
Gradle__com_android_support_appcompat_v7_27_1_1.xml 690B
Gradle__junit_junit_4_12_jar.xml 495B
Gradle__com_android_support_test_monitor_1_0_2.xml 670B
Gradle__com_android_support_support_vector_drawable_27_1_1.xml 745B
Gradle__android_arch_lifecycle_runtime_1_1_0.xml 666B
Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml 565B
Gradle__javax_inject_javax_inject_1_jar.xml 536B
Gradle__com_android_support_support_fragment_27_1_1.xml 710B
Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml 551B
Gradle__com_android_support_constraint_constraint_layout_1_1_2.xml 509B
Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml 586B
Gradle__android_arch_lifecycle_viewmodel_1_1_0.xml 676B
Gradle__com_google_code_findbugs_jsr305_2_0_1_jar.xml 367B
Gradle__com_android_support_animated_vector_drawable_27_1_1.xml 750B
Gradle__android_arch_core_runtime_1_1_0.xml 655B
Gradle__android_arch_core_common_1_1_0_jar.xml 541B
Gradle__com_android_support_test_runner_1_0_2.xml 665B
caches
build_file_checksums.ser 545B
workspace.xml 222KB
gradle.xml 626B
codeStyles
Project.xml 2KB
runConfigurations.xml 564B
modules.xml 361B
gradle
wrapper
gradle-wrapper.properties 236B
gradle-wrapper.jar 53KB
ImageEditV01.iml 866B
local.properties 373B
共 80 条
- 1
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0
最新资源