Display images asynchronously in listfield blackberry - blackberry

While loading images from url in every row of a listfield,default image should be display until image is fetched. Then fetched image should be displayed. How to do this? please help.
I was trying following code but failed
if(HttpUtils.getBitmap(url1)==null)
{
final Bitmap b1 = Bitmap.getBitmapResource("images.jpg");
g.drawBitmap(0, y+5, b1.getWidth(),b1.getHeight(),b1, 0, 0);
}

Related

Deleting an image in a Google Doc Table after placing and then resizing the image

I have searched and found code that first inserts an image into a Table in a Google Doc.The image however is larger than the desired image space--and so we have to resize the picture by first getting the dimensions of the inserted picture and then reinserting the picture into the table. The code seems to work well except I am left with two pictures the original sized picture and the scaled picture in the specified table location.
My challenge is that when I attempt to delete the first picture after getting the sizing information needed to scale the picture -- nothing ends up being saved. Here is the code:
if(celltext === "%PIC%") {
table.replaceText("%PIC%", "");
table.getCell(row, cell).insertImage(0, image);
sizePic(table,image, row,cell);
}
function sizePic(table, image) {
var cellImage = table.getCell(row, cell).insertImage(0, image);
//get the dimensions of the image AFTER having inserted it to fix
//its dimensions afterwards
var originW = cellImage.getWidth();
var originH = cellImage.getHeight();
var newW = originW;
var newH = originH;
var ratio = originW/origin
var styleImage = {};
var maxWidth = 200;
if(originW>maxWidth){
newW = maxWidth;
newH = parseInt(newW/ratio);
table.getCell(row,cell).clear();
}
cellImage.setWidth(newW).setHeight(newH).setAttributes(styleImage);
}
}
The problematic line is the table.getCell(row,cell).clear(); that even though it occurs after the image is inserted and before the sized image is inserted, it doesn't appear to work that way. Please note that my code is the result of looking at an existing post How to resize image on Google app Script.

Shrink image in iphone 7 xamarin ios?

I am working in xamarin.ios. I am capturing a picture with help of camera and trying to upload it on server. But when I am trying to upload it on server I am getting "TargetInvocationException". But when I am running same code on Ipad everything is working fine.
Following is the code :
Camera.TakePicture(this, (obj) =>
{
var photo = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage;
Byte[] myByteArray;
using (NSData imageData = photo.AsJPEG(0.0f))
{
//myByteArray = imageData.ToArray();
myByteArray = new Byte[imageData.Length];
System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
}
ImageLoaderPopup imageLoader = new ImageLoaderPopup(this, selectedWorkOrder, myByteArray, title);
imageLoader.PopUp(true, delegate { });
});
Does anyone know why I am facing this problem? What am I doing wrong?
You might be having problem with the size of the image returned by the Picker. Images taken with the iPhone 7 are huge in size.
You just need to scale down the original image before uploading it using the Scale method and setting the size you find acceptable.
var smallImage = image.Scale(new CGSize(1280, 720)); //Or the size you need.
UPDATE
All you need is the Scale method mentioned above.
The big advantage of Xamarin being Open Source is that you can look at the internals any time you have a doubt.
https://github.com/xamarin/xamarin-macios/blob/master/src/UIKit/UIImage.cs#L66

how to do image resize without distortion in Blackberry

I am downloading an image from the web and applying fixed32 method to resize the image to fit to screen. Resizing the image causes some loss of clarity, but my client wants to display the image without this distortion. How can I do this?
The way I do this is to not resize the image in the phone. I request my server to send me image based on the width*height I need. The server then resizes the image for me. How about you try a similar solution. This would help you by providing a proper resized image, and improve performance of your app.
Use following method for resizing image.
public static Bitmap SizePic (EncodedImage Resizor,int Height, int Width) {
int multH;
int multW;
int currHeight = Resizor.getHeight();
int currWidth = Resizor.getWidth();`enter code here`
multH= Fixed32.div(Fixed32.toFP(currHeight),Fixed32.toFP( Height));
multW = Fixed32.div(Fixed32.toFP(currWidth),Fixed32.toFP(Width));
Resizor = Resizor.scaleImage32(multW,multH);
return Resizor.getBitmap();
}

How to override downloaded image with default image to black berry list field

From the past two days i am doing list field with web image in black berry,because i am new.
I am displaying list field with some default image.when i dowloaded the actual image from web it can't replacing on default image.I used one thread to load images one by one.But images are not overriding with default image properly.Please help me.Here is my code
of list field.
public void drawListRow(ListField listField,final Graphics graphics,int index,
final int y, int width)
{
this.graphics=graphics;
this.inde=index;
class ImageDowload extends Task
{
void doTask()
{
load=new DowloadImage(picture[inde]);
if(load.getData()!=null)
{
_bmap=load.getBitmap();
graphics.drawBitmap(3,y+7,placeholder.getWidth(), placeholder.getHeight(),_bmap, 0, 0);
}
}
}
taskWorker.addTask(new ImageDowload());
String text=(String) get(listField, index);
String pricedetails=price[index];
graphics.setColor(rgb);
graphics.setFont(Utility.getBigFont(DConfig.getFSize()+4));
graphics.drawBitmap(3,y+7,placeholder.getWidth(), placeholder.getHeight(),placeholder, 0, 0);
graphics.drawText(text,100,y+25);
graphics.drawText(pricedetails+" $",420,y+25);
graphics.drawLine(0, y+74, DConfig.disWidth, y+74);
}
You definitely don't want to be putting your ask in the drawListRow(), as it's going to fire every time it has to repaint.
Just start the downloading for all images when you create the ListField (or any time that makes sense). In your drawListRow() when you go to paint the Bitmap, check if the downloaded one exists, and if it does draw that, if not draw the default. Now as each image download is complete, just invalidate() the ListField and it will draw the newly downloaded image.

how I can place an image just in one cell using npoi

I'm using npoi to generate excel docs. I have a requirement to add images to cells. Using the following code i can insert images into my doc. However the image span many cells. How can i ensure that the image just fits inside once cell.
public ActionResult NPOICreate()
{
try
{
FileStream fs = new FileStream(Server.MapPath(#"\Content\NPOITemplate.xls"), FileMode.Open, FileAccess.ReadWrite);
HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs, true);
var sheet = templateWorkbook.GetSheet("Sheet1");
var patriarch = sheet.CreateDrawingPatriarch();
HSSFClientAnchor anchor;
anchor = new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 5);
anchor.AnchorType = 2;
var picture = patriarch.CreatePicture(anchor, LoadImage(#"D:\dev\Website/HumpbackWhale.jpg", templateWorkbook));
picture.Resize();
picture.LineStyle = HSSFPicture.LINESTYLE_DASHDOTGEL;
sheet.ForceFormulaRecalculation = true;
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
TempData["Message"] = "Excel report created successfully!";
return File(ms.ToArray(), "application/vnd.ms-excel", "NPOINewFile.xls");
}
catch (Exception ex)
{
TempData["Message"] = "Oops! Something went wrong.";
return RedirectToAction("NPOI");
}
}
To the best of my knowledge, it isn't possible to assign an image object to a particular cell within Excel.
This is not a limitation of POI/NPOI, but rather the way Excel works: Pictures inserted into a spreadsheet just float (over the spreadsheet grid per se)...
At best one can make believe it is in the cell by ensuring that the size and position of the cell and of the picture match perfectly. There is a property of the picture (See "Format Picture" dialog, Properties section, also accessible through POI I'm sure) which allows to specify whether the picture will move and/or resize itself following actions on rows/cells surrounding it, but in the end, pictures remain a floating object very loosely related to a cell at best.
A common trick to assign a picture to a cell is by way of comments. The picture is then more formally bound to the cell but it is not shown as content but rather a comment data.
See for example this recipe. The idea is to use the background of the comment to be a color with a special fill effect which is the picture we wish to associate with the cell. Here again, there's got to be a way of achieving this programmatically with NPOI, but I cannot affirm this firsthand.
here's something you can try:
You see that property, anchor.AnchorType = 2;? try setting that to 0 or 3 and see what it does. In the C# (NPOI) port, 0 will fit the image in just one cell with option 0.
Here's some example code (used in a C# Asp.net project, just in case someone wanders here that needs it):
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
HSSFSheet sheet1 = hssfworkbook.CreateSheet(sheetName);
//map the path to the img folder
string imagesPath = System.IO.Path.Combine(Server.MapPath("~"), "img");
//grab the image file
imagesPath = System.IO.Path.Combine(imagesPath, "image.png");
//create an image from the path
System.Drawing.Image image = System.Drawing.Image.FromFile(imagesPath);
MemoryStream ms = new MemoryStream();
//pull the memory stream from the image (I need this for the byte array later)
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
//the drawing patriarch will hold the anchor and the master information
HSSFPatriarch patriarch = sheet1.CreateDrawingPatriarch();
//store the coordinates of which cell and where in the cell the image goes
HSSFClientAnchor anchor = new HSSFClientAnchor(20, 0, 40, 20, 3, 10, 4, 11);
//types are 0, 2, and 3. 0 resizes within the cell, 2 doesn't
anchor.AnchorType = 2;
//add the byte array and encode it for the excel file
int index = hssfworkbook.AddPicture(ms.ToArray(), HSSFPicture.PICTURE_TYPE_PNG);
HSSFPicture signaturePicture = patriarch.CreatePicture(anchor, index);
It's possible by three steps.
First, you should insert the picture
Second, add the ClientAnchor to the file to locate the picture to some cells
Third, resize the picture using tricky way otherwise it's hard to make a picture inside a cell

Resources