2

I am trying to build a drawing tool, this drawing tool allow users to select images and place them in a sketch which afterwards they can be manipulated within. All images that belong to the project have been set to the same scale (1:100): the steps the program follows to create the work area are the following, first a dialog pops up and ask user to enter work area in X axis:

//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());

Scale is set up with whatever the function setSizeWorkAre returns:

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);

This method converts pixels to Meters:

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));
}

Then I get the screen resolution:

// 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));

Now that I set up the screen working area, I proceed to place the images:

ImageView newImage = new ImageView(getContext());
//set properties for imageView                                                   
newImage.setScaleType(ImageView.ScaleType.CENTER);                                          
newImage.setAdjustViewBounds(true);
newImage.setDrawingCacheEnabled(true);
newImage.setOnTouchListener(this); 

This is where the image gets re-scaled

imgViewSelected.getLayoutParams().width = (int) 
MyConvert.scaleValue(newImage.getDrawable().getIntrinsicWidth());

imgViewSelected.getLayoutParams().height = (int) 
MyConvert.scaleValue(newImage.getDrawable().getIntrinsicHeight());

and the scaleValue method:

public static float scaleValue(float value){
float resScale= getScale()/122;

float salida=    value/resScale;
     return salida; 
}

This is working all good until I select one image that has bigger size than the screen resolution, is like if android were re scaling automaticly and then doing another re scale from my instructions.

Some images to give an idea of what is happening:

In this image, it appears to be working as it should, when working area is set to 40 or more (mts) it looks better, the greater the value the better the approach

In this case area is set to 30 (mts) and you can see how it is re scaling the image to a smaller, remember it only happens with images larger than screen res

is there any image handler expert out there? any hints on this matter will be highly appreciated.

Jhonycage
  • 759
  • 3
  • 16
  • 36

1 Answers1

1

Use Frame layout that wraps the Image to be inserted.

Example:

<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 or Scroll View don´t get limitations by screen size, so your image won´t be re-scaled by Android.

Edwin gamboa
  • 26
  • 1
  • 2