我正在嘗試構建一個繪圖工具,該繪圖工具允許用戶選擇圖像並將它們放入草圖中,之後可以在其中進行操作。 所有屬於該項目的圖像都被設置爲相同比例(1:100):程序創建工作區所遵循的步驟如下,首先彈出一個對話框並要求用戶在X軸上輸入工作區:ImageView大於屏幕分辨率被重新縮放錯誤
//prompts user for area size
String areaX = txtLargeArea.getText().toString();
//parse to int
int area = Integer.parseInt(areaX);
if (area > 14 && area < 101) {
//set atributes from MyConvert Class
// 15 is a fixed size for Y axis
MyConvert.setAreaSelected(new PointF(area, 15));
MyConvert.setScale(MyConvert.setSizeWorkAre());
量表設置爲與任何功能setSizeWorkAre返回:
public static float setSizeWorkAre() {
PointF offsetMtrs = PixsToMts(offset);//65x100 are default value to set the offset point for the plot
scale = 1;
PointF screenInMts = PixsToMts(screenResolution);
return ((areaSelected.x + offsetMtrs.x)/screenInMts.x);
此方法轉換像素爲米:
public static PointF PixsToMts(PointF coordenate) {
return new PointF((float) ((((coordenate.x * 2.54)/dpi) * scale)/100),
(float) ((((coordenate.y * 2.54)/dpi) * scale)/100));
}
然後我得到的屏幕分辨率:
// class that allows to obtain info about device
DisplayMetrics metrics = getResources().getDisplayMetrics();
//set atributes from MyConvert class
MyConvert.setDpi(metrics.densityDpi);
MyConvert.setScreenResolution(new
PointF(metrics.widthPixels,metrics.heightPixels));
現在,我設置的屏幕工作區域,我開始放置圖片:
ImageView newImage = new ImageView(getContext());
//set properties for imageView
newImage.setScaleType(ImageView.ScaleType.CENTER);
newImage.setAdjustViewBounds(true);
newImage.setDrawingCacheEnabled(true);
newImage.setOnTouchListener(this);
這就是形象得到重新縮放
imgViewSelected.getLayoutParams().width = (int)
MyConvert.scaleValue(newImage.getDrawable().getIntrinsicWidth());
imgViewSelected.getLayoutParams().height = (int)
MyConvert.scaleValue(newImage.getDrawable().getIntrinsicHeight());
和scaleValue方法:
public static float scaleValue(float value){
float resScale= getScale()/122;
float salida= value/resScale;
return salida;
}
直到我選擇一個尺寸大於屏幕分辨率的圖像時,它才能正常工作,就像android自動縮放,然後從我的指令中重新縮放。
一些影像,讓正在發生的事情的想法:
在此圖像中,這似乎是工作,因爲它應該在工作區域被設置爲40個或更多(MTS),它看起來更好,更大值的方法
在設置爲30(MTS),這種情況下,區域較好的,你可以看到它是如何重新將圖像縮放到一個較小的,記住這只是比屏幕清晰度較大的圖像發生
有沒有圖像處理專家在那裏?有關此事的任何提示將不勝感激。
工程就像一個魅力,大起來 – Juanca