私はアンドロイドスタジオで働いています。私は自分の電話機からディレクトリから写真をインポートし、それをImageViewに配置するためにtriyngです。私のimageViewは動作しません
私の最初の活動では、カメラを使って写真を保存しようとしましたが、写真からURIを保存しようとしました。それは働いている。
他のアクティビティでは、そのURIをインポートしようとしましたが、ImageViewは変更されません。コンパイラが写真の場所を見たので、作業中だと思いますが、画像ビューでは写真をインポートできません。
私を助けてくれますか?
public class PictureConfirmation extends Activity {
ImageButton use;
ImageButton retake;
TextView usetxt;
TextView retaketxt;
ImageView pictaken;
String pic;
File picfile;
Matrix matrix;
String pic2;
Bitmap bitmap;
public Bitmap rotatedbitmap;
ImageButton scan;
ImageView teeth;
TextView scantxt;
public String colorRGB;
TextView canceltxt;
Uri ImgUri;
public float ax;
public float ay;
int Rc, Gc, Bc;
public int checkcamera=0;
TextView colortxt;
@Override
protected void onCreate(Bundle savedInstance) {
final Typeface bariol_font = Typeface.createFromAsset(getAssets(), "Bariol_Bold.otf");
//going full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstance);
setContentView(R.layout.picture_confirmation);
final String PREF_NAME = "Link";
String defaultValue = "default string";
Preferences prefs = Preferences.userNodeForPackage(com.example.newrosoft1.dentafy.MainMenuActivity.class);
String propertyValue = prefs.get(PREF_NAME, defaultValue); // "a string"
//pic = new MainMenuActivity().getpath();
pic2=propertyValue;
pic=propertyValue;
Log.d("valoare este %@" ,pic.toString());
//bitmap =BitmapFactory.decodeFile(pic);
// Uri imgUri=Uri.parse(pic);
//.setImageURI(imgUri);
use = (ImageButton) findViewById(R.id.usebtnid);
retake = (ImageButton) findViewById(R.id.retakebtnid);
retaketxt = (TextView) findViewById(R.id.retaketxtid);
retaketxt.setTypeface(bariol_font);
usetxt = (TextView) findViewById(R.id.usetextid);
usetxt.setTypeface(bariol_font);
pictaken = (ImageView) findViewById(R.id.pictakenid);
//pictaken.setImageBitmap(bitmap);
Uri imgUri=Uri.parse(pic);
pictaken.setImageURI(null);
pictaken.setImageURI(imgUri);
try {
pictaken.setImageDrawable(Drawable.createFromStream(
getContentResolver().openInputStream(imgUri),
null));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
final AlertDialog.Builder alertdialog = new AlertDialog.Builder(this);
alertdialog.setTitle("Confirmation");
alertdialog.setMessage("Are you sure this is the correct picture?\nPlease note that you have a limited number of scans");
alertdialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setContentView(R.layout.processing);
Runnable r = new Runnable() {
@Override
public void run() {
setContentView(R.layout.scan_teeth_finished);
TextView done = (TextView) findViewById(R.id.donetxtid);
done.setTypeface(bariol_font);
colortxt = (TextView) findViewById(R.id.teethcolortxtid);
colortxt.setTypeface(bariol_font);
teeth = (ImageView) findViewById(R.id.teethimg);
//teeth.setImageBitmap(bitmap);
Uri imgUri=Uri.parse(pic);
teeth.setImageURI(null);
teeth.setImageURI(imgUri);
try {
teeth.setImageDrawable(Drawable.createFromStream(
getContentResolver().openInputStream(imgUri),
null));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
teeth.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
float[] eventXY = new float[]{eventX, eventY};
Matrix invertMatrix = new Matrix();
((ImageView) view).getImageMatrix().invert(invertMatrix);
invertMatrix.mapPoints(eventXY);
int x = Integer.valueOf((int) eventXY[0]);
int y = Integer.valueOf((int) eventXY[1]);
Drawable imgDrawable = teeth.getDrawable();
bitmap = ((BitmapDrawable) imgDrawable).getBitmap();
//Limit x, y range within bitmap
if (x < 0) {
x = 0;
} else if (x > (bitmap.getWidth() - 1)) {
x = bitmap.getWidth() - 1;
ax = x;
}
if (y < 0) {
y = 0;
} else if (y > (bitmap.getHeight() - 1)) {
y = bitmap.getHeight() - 1;
ay = y;
}
int touchedRGB = bitmap.getPixel(x, y);
int[] areapixels = new int[bitmap.getWidth() * bitmap.getHeight()];
int touchedAreaRGB;
try {
bitmap.getPixels(areapixels, 0, bitmap.getWidth(), x, y, 25, 25); //pixel area to scan
} catch (ArrayIndexOutOfBoundsException arrayindexoutofbounds) {
Toast.makeText(getApplicationContext(), "index out of bounds exception",
Toast.LENGTH_SHORT).show();
} catch (IllegalArgumentException illegalargumentexception) {
}
int total = 0;
for (int i = 0; i < areapixels.length; i++) {
if (areapixels[i] != 0)
{
Rc += (areapixels[i] >> 16) & 0xff;
Gc += (areapixels[i] >> 8) & 0xff;
Bc += (areapixels[i]) & 0xff;
total++;
}
}
if (Rc != 0 || Gc != 0 || Bc != 0) {
Rc /= total;
Gc /= total;
Bc /= total;
}
touchedAreaRGB = 0xff000000 | (Rc << 16) | (Gc << 8) | Bc;
int avrgColor = (Gc - Bc) * 10/2;
int yellow = 12229738;
int white = 16777215;
int value = ((touchedRGB - yellow) * 100)/(white - yellow);
int value2 = ((touchedRGB - yellow) * 10)/(white - yellow);
Log.d("value: ", "asd100 " + value);
Log.d("value: ", "asd10 " + value2);
colorRGB = "could not find color code, tap again " + value2;
if (value2 < 32)
colorRGB = "Selected tooth color is:A1";
switch (value2) {
case -33:
colorRGB = "Selected tooth color is:A1 ";
break;
case -32:
colorRGB = "Selected tooth color is:B1";
break;
case -35:
colorRGB = "Selected tooth color is:A2 ";
break;
case -36:
colorRGB = "Selected tooth color is:A3 ";
break;
case -34:
colorRGB = "Selected tooth color is:B2 ";
break;
case -38:
colorRGB = "Selected tooth color is:D2 ";
break;
case -37:
colorRGB = "Selected tooth color is:D3 ";
break;
case -40:
colorRGB = "Selected tooth color is:D4 ";
break;
}
colortxt.setText(colorRGB);
if (Gc < Bc || Gc < 100) {
// Toast.makeText(getApplicationContext(), "Could not get color code, make sure you tap on tooth", Toast.LENGTH_SHORT).show();
}
//colorRGB.setText("Selected tooth color is:C1" + value2);
Rc = 0;
Bc = 0;
Gc = 0;
total = 0;
return true;
}
});
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(PictureConfirmation.this, MainMenuActivity.class));
}
});
}
};
Handler h = new Handler();
h.postDelayed(r, 2000);
}
});
alertdialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do nothing
}
});
alertdialog.create();
//pictaken.setImageBitmap(bitmap);
//Uri imgUri=Uri.parse(pic);
pictaken.setImageURI(null);
pictaken.setImageURI(imgUri);
retake.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// startActivity(new Intent(PictureConfirmation.this, CameraMainActivity.class));
}
});
use.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.scan_teeth_start);
scan = (ImageButton) findViewById(R.id.scanbtnid);
teeth = (ImageView) findViewById(R.id.teethimageid);
scantxt = (TextView) findViewById(R.id.startscantxtid);
scantxt.setTypeface(bariol_font);
canceltxt = (TextView) findViewById(R.id.canceltxtid);
canceltxt.setTypeface(bariol_font);
//teeth.setImageBitmap(bitmap);
Uri imgUri2=Uri.parse(pic);
teeth.setImageURI(null);
teeth.setImageURI(imgUri2);
canceltxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(PictureConfirmation.this, MainMenuActivity.class));
}
});
// matrix.postRotate(270);
// bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // rotating bitmap
scan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertdialog.show();
}
});
}
});
}
}
ここにlogcatを投稿してください。イメージビューを含むxmlファイル – Aakash
このデモの例を参照してください:http://programmerguru.com/android-tutorial/how-to-pick-image-from-gallery/ –
あなたの画像はどこにありますか –