Suppose i have an animated GIF image name test.GIF added to my project in BlackBerry JDE to be used in AnimatedGIFField class. and now i need to convert it to Encoded image.
In the reference it is given to create encoded image the following function
public static EncodedImage createEncodedImage(byte[] data,
int offset,
int length)
Plz give me the code to convert test.GIF to encoded image????
use this code
EncodedImage encImg = GIFEncodedImage.getEncodedImageResource("test.gif");
if you need GIFEncodedImage then cast encImg to GIFEncodedImage.
GIFEncodedImage img = (GIFEncodedImage) encImg;
By the way, casting EncodedImage to GIFEncodedImage fails on OS7. You have to rename your gif extension to .agif to make it work.
Related
I have a view that has a large embedded image, like this:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSU.......YII=" />
When the image is too large the scr attribute is very large (it can have 2 mega characteres) I get the error:
CS1647: An expression is too long or complex to compile
But, if the src attribute has less characteres (ex: 300,000 characteres) the view works perfectly.
How can I use large embedded images in a razor view?
You only shold use base64 images when the image is small.
You can try converting the base64 string to an image using this:
public Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
return image;
}
if your image is a static resource you can try put it in a <text> or :#
<text>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSU.......YII=" />
</text>
I'm currently trying to load a simple bitmap using XNA but I get the following error:
Error loading "Maps\standard". File contains Microsoft.Xna.Framework.Graphics.Texture2D but trying to load as System.Drawing.Bitmap.
code:
public Bitmap map;
public void load(Game game, String image) {
path = image; //path to image
map = game.Content.Load<Bitmap>("Maps/"+path);
sizeX = map.Width;
sizeY = map.Height;
}
You want the below:
map = game.Content.Load<Texture2D>("Maps/"+path);
The way XNA works is that there is a content pipeline, which takes inputs (like your bitmap image) and produces outputs (the Texture2D), which is in a different format to the input.
XNA works with a Texture2D object when displaying images.
Now, I just use the C# standard
Bitmap bmp = (Bitmap)Bitmap.FromFile(path);
I have an algorithm in created in c++ to make background subtraction, and i want to call it from c# with an argument "IplImage" using dll(extern). The problem that i acquire the camera stream in c# and i have the frame as image (bitmap).
How could i convert the bitmap to IplImage to send it in c++ and vice versa to retrieve the frame treated?
Many thanks.
Using Emgucv, you can try
Bitmap bitmap = ....
Emgu.CV.Image<Bgr, Byte> img = new Image<Bgr, byte>(bitmap);
Emgu.CV.Structure.MIplImage = img.MIplImage;
to send it in C++ method you can pass it as IntPtr object
IntPtr r = IntPtr.Zero;
System.Runtime.InteropServices.Marshal.StructureToPtr(img, r, false);
// call your c++ method
...
also see detail about Marshal
I need to process images which i get from OpenCV.
I wrote so far:
IplImage* img=0;
img=cvLoadImage("paket2.tif");
api.SetRectangle(0,0,img->width, img->height);
api.SetImage((uchar*)img->imageData,img->width,img->height,img->depth/8,img->width*(img->depth/8));
//i tried also below line
//api.SetImage((uchar*)img->imageData,img->width,img->height,img->depth/8,img->widthStep);
int left,top,right,bottom;
left=0;top=0;right=0;bottom=0;
api.Recognize(NULL);
tesseract::ResultIterator *ri=api.GetIterator();
char * sonuc=(*ri).GetUTF8Text(tesseract::RIL_SYMBOL);
if((*ri).BoundingBox(tesseract::RIL_SYMBOL,&left,&top,&right,&bottom))
{printf("bb dogru\n");printf("%d,%d,%d,%d",left,top,right,bottom);}
printf("sonuc:%s",sonuc);
if i pass IplImage->widthStep to bytes perline, i have "wrong" boundingBox in left and right values and can not read all the text in the image.
if i pass IplImage->width*(IplImage->depth/8), boundingBox function returns false.
I hope you have some idea.
Thanks in advance.
Copy your submatrix to a new IplImage. Create a tesseract image header with the correct info(width, height, step). Link the tesseract data pointer to the iplImage data pointer.
I can't remember how to access tesseract pointer, but for opencv is image->data.ptr
This code here worked for me:
tesseract::TessBaseAPI tess;
tess.Init(argv[0], "eng", tesseract::OEM_DEFAULT);
cv::Mat image = cv::imread("...");
tess.SetImage((uchar*)image .data, image.size().width, image.size().height, image.channels(), image.step1());
tess.Recognize(0);
const char* out = tess.GetUTF8Text();
I have a pointer to image:
IplImage *img;
which has been converted to Mat
Mat mt(img);
Then, the Mat is sent to a function that gets a reference to Mat as input void f(Mat &m);
f(mt);
Now I want to copy back the Mat data to the original image.
Do you have any suggestion?
Best
Ali
Your answer can be found in the documentation here: http://opencv.willowgarage.com/documentation/cpp/c++_cheatsheet.html
Edit:
The first half of the first code area indeed talks about the copy constructor which you already have.
The second half of the first code area answers your question. Reproduced below for clarity.
//Convert to IplImage or CvMat, no data copying
IplImage ipl_img = img;
CvMat cvmat = img; // convert cv::Mat -> CvMat
For the following case:
double algorithm(IplImage* imgin)
{
//blabla
return erg;
}
I use the following way to call the function:
cv::Mat image = cv::imread("image.bmp");
double erg = algorithm(&image.operator IplImage());
I have made some tests and how it looks the image object will manage the memory. The operator IplImage() will only construct the header for IplImage. Maybe this could be useful?
You can use this form:
Your Code:
plImage *img;
Mat mt(img);
f(mt);
Now copy back the Mat data to the original image.
img->imageData = (char *) mt.data;
You can also copy the data instead of pointer:
memcpy(mt.data, img->imageData, (mt.rows*mt.cols));
(mt.rows*mt.cols) is the size that you should use for copy all data the mt to img.
Hope I helped