Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in ButtonField and BitmapField

Hi

Yes the image is the string.

For updating the profile image i have given a link, in that link i have to pass the user id and i response i am getting the status and message.

I am confused if i edit the bitmapfield and click the save button then the profileImage link gets called instead of the other link. So how do i compare the bitmap and buttonfield.?

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in ButtonField and BitmapField

I appreciate the English is not your first language, but I not understanding what you are saying.

 

How do you get the image that is currently being used?  Please give us this in detail. 

 

"For updating the profile image i have given a link"

Do you mean you have been given a URL?  I presume so.  Have you been given instructions regarding how you send the profile update back?  Can you summarise these instructions for us. 

 

"I am confused if i edit the bitmapfield and click the save button then the profileImage link gets called instead of the other link"

This makes no sense to me. 

 

"So how do i compare the bitmap and buttonfield.?"

Why do you need to compare these?

Please use plain text.
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in ButtonField and BitmapField

[ Edited ]

Hi

See i have a profile page that contains:

Profile image  any image     //if edit go to url2

First name: ABC     //if edit go to url1

Last name: XYZ      //if edit go to url1

Email id: abc@xyz.com       //if edit go to url1

Phone no: 1234567890     //if edit go to url1

                                                      Save button

 

Now what i want if i edit ant field say i edit the phone no field

Phone no : 456789456789

and click on save button

then this phone no send to url1 and saved on server.

 

Now i add the new image as Profileimage: image2

and click on save button  

then this image send to url2 and saved on server.

 

 

if(field== save)

{

Thread1 t1= new Thread1();

t1.start();

}

 

class Thread1 extends Thread

{

public void run()
{
System.out.println("Connection Thread Started.....");
synchronized (UiApplication.getEventLock())
{
try
{
Thread.sleep(10);
}
catch (InterruptedException e)
{
e.printStackTrace();
}

Dialog dialog1 = new Dialog("Saving...", new String[]{}, new int[]{}, 0, null,Screen.DEFAULT_CLOSE);
UiApplication.getUiApplication().pushScreen(dialog1);
}


if(.......)   //what should i add here so that if i edit any field it goes to url1

{

url1

}

else    //image updating url

{

url2

}

super.run();
}

}

 

 

I hope my question is clear now.??

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in ButtonField and BitmapField

[ Edited ]

OK so you have two different URLs, I recommend that you have two different buttons so you know if the Profile image has been updated.  Otherwise you need to detect when this has changed.  You only want to send the image data when it really has changed and the user wants to make this permanent.

 

Let us forget the profile image for the moment since you seem to be having problems with the text updates, which are simpler.  So we can get this working for you and that will then make the image updating easier for you to understand.  And I see you are asking about this on a separate Thread (http://supportforums.blackberry.com/t5/Java-Development/Problem-in-sending-jpg-and-png-image-to-serv...) anyway.

 

Now normally when doing this sort of update, you update everything to match what the user is currently seeing.  So you will get the text from your Fields, and send then to the Server (URL1).  I've no idea what format you need to send these in, the format will depend entirely on what your Server expects - there is no consistent method that works for all Server. 

 

So, for URL1 only (the text) can you answer the two related questions from my last post:

"Have you been given instructions regarding how you send the profile update back?  Can you summarize these instructions for us. "

 

In addition, it looks like you are struggling to understand network communication, so I recommend you do some research on here, perhaps reviewing this:

http://supportforums.blackberry.com/t5/Java-Development/Networking-Transports-II/ta-p/446742

and the httpDemo sample as starters. 

Please use plain text.
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in ButtonField and BitmapField

Actually sending data and image to server is not an issue.

The problem is in if statement

if(.......)   //what should i add here so that if i edit any field it goes to url1

{

url1

}

else    //image updating url

{

url2

}

 

I can't make two buttons. I have to send the data to sever of and only if i click on save button.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in ButtonField and BitmapField

You have to detect when the user changes the field yourself, and then you might have to send to URL1 or URL2 or both.  The easiest way to do it this for the text input fields is to remember what you set each Field to and compare that with what is currently there.  For the BitmapField, you will know if the user has clicked on it because you are detecting that, so you can set a flag at that time. 

Please use plain text.
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in ButtonField and BitmapField

Hi

I have facing 1 more problem.

The image i am receiving from the server has 100X100 dimensions.

But i am placing it on 180X180 bitmapField. The image gets blured.

I am using

 

protected Bitmap resizeImage(Bitmap bitmap,int width,int height)
        {
            PNGEncodedImage pngEncodedImage = PNGEncodedImage.encode(bitmap);
            int scaledWidth = Fixed32.div(Fixed32.toFP(bitmap.getWidth()), Fixed32.toFP(width));
            int scaledHeight = Fixed32.div(Fixed32.toFP(bitmap.getHeight()),Fixed32.toFP(height));
            EncodedImage encodeImage = pngEncodedImage.scaleImage32(scaledWidth, scaledHeight);
            return encodeImage.getBitmap();
        }

even the i am getting the blured image.

 

Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Problem in ButtonField and BitmapField

Try this code:

public static EncodedImage sizeImage(EncodedImage image, int width, 
            int height) 
    {
		EncodedImage result = null;
		
		int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
		int currentHeightFixed32 = Fixed32.toFP(image.getHeight());

		int requiredWidthFixed32 = Fixed32.toFP(width);
		int requiredHeightFixed32 = Fixed32.toFP(height);
		
		int scaleXFixed32 = Fixed32.div(currentWidthFixed32,
				requiredWidthFixed32);
		int scaleYFixed32 = Fixed32.div(currentHeightFixed32,
				requiredHeightFixed32);

		result = image.scaleImage32(scaleXFixed32, scaleYFixed32);
		return result;
    }
    
    public static Bitmap cropBitmap(Bitmap original, int width, int height) 
    {
        Bitmap bmp = new Bitmap(width, height);
        int x = (original.getWidth() / 2) - (width / 2); // Center the new size by width
        int y = (original.getHeight() / 2) - (height / 2); // Center the new size by height
        int[] argb = new int[width * height]; 
        original.getARGB(argb, 0, width, x, y, width, height);
        bmp.setARGB(argb, 0, width, 0, 0, width, height);
        return bmp;
    }

 and add this in bitmap like this:

EncodedImage  eImage	=	EncodedImage.getEncodedImageResource("image.png");
      	EncodedImage bitimage	=	sizeImage(eImage,180,180);
      	Bitmap image			=	cropBitmap(bitimage.getBitmap(),180,180);

 it will make ur image 180*180

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in ButtonField and BitmapField

The code supplied by developer_aman_arora will not help here.  It will have the same problem as you currently have.

 

The issue here is simply that scaling up an image will usually give you ;artifacts' and a lose of sharpness.  Imagine you are scaling up your 100x100 image, to 200x200.  The easiest way to do this is to make what is 1x1 pixel square in the old image take up the space of a 2x2 square.  So you keep the same colors everywhere, but each color just becomes twice as big.  The result will look blurred.

 

The better the scaling algorithm you use the more it will try to compensate for this and make things less blurred, but they take longer.  AFAIK, the best algorithm on the device are used when you do

Bitmap scaleInto

So have a look at that and see if that is less blurry.

 

To be honest, I doubt it, so I think you will have to put up with this blurry image or get an image from the Server which is a larger size. 

Please use plain text.
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in ButtonField and BitmapField

Hi

i am still getting the blured image

 

 

Bitmap defaultImage=connectServerForImage(imageName);   //i am getting the bitmap image
  Bitmap   Profileimage=scale(defaultImage, 180, 180);
   Bitmap  profileBitmapField = new BitmapField(Profileimage,BitmapField.FOCUSABLE);

 

public Bitmap scale(Bitmap bitmap,int w,int h)

{

   Bitmap scaleBitmap=new Bitmap(w,h);
                bitmap.scaleInto(scaleBitmap, Bitmap.FILTER_LANCZOS);

 

return scaleBitmap;

}

Please use plain text.