2017-04-05 92 views
1

我正在尝试构建一个绘图工具,该绘图工具允许用户选择图像并将它们放入草图中,之后可以在其中进行操作。 所有属于该项目的图像都被设置为相同比例(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),这种情况下,区域较好的,你可以看到它是如何重新将图像缩放到一个较小的,记住这只是比屏幕清晰度较大的图像发生

有没有图像处理专家在那里?有关此事的任何提示将不胜感激。

回答

1

使用包装要插入的图像的框架布局。

例子:

<FrameLayout 
      android:id="@+id/yourid" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     </ImageView> 


</FrameLayout> 

的FrameLayout或滚动查看鸵鸟政策得到屏幕尺寸的限制,所以你的形象将不会致使由Android重新缩放。

+0

工程就像一个魅力,大起来 – Juanca