I want to display bmp image and text in list control in MFC ,
It should display different bmp image for different item , but it display same bmp for all the items
Here is my code
CListCtrl m_cParentListContrl;
CImageList m_ImageList[3];
m_ImageList[0].Create(IDB_BMP_LISTCTRL,128,1,RGB(150,150,100));
m_ImageList[1].Create(IDB_BMP_CHECKBOX,128,1,RGB(150,150,100));
m_ImageList[2].Create(IDB_BMP_COMBOBOX,128,1,RGB(150,150,100));
m_cParentListContrl.SetImageList(m_ImageList,LVSIL_NORMAL);
for(int i = 0 ; i < 3 ; i++)
{
val.Format(_T("List ::%d"),i);
//third parameter for index of image to be displayed
// if that replaced by i to 0 then it display single image else not
m_cParentListContrl.InsertItem(i,val,i);
}
Thanks
Assuming you don't want to reduce your current 3 bitmaps to one continuous strip bitmap with your 3 images one after each other:
CImageList m_ImageList;
m_ImageList.Create(128,128, ILC_COLOR24, 3, 1);
m_ImageList.SetImageCount(3);
CBitmap bmpListCtrl;
bmpListCtrl.LoadBitmap(IDB_BMP_LISTCTRL);
m_ImageList.Replace(0, bmpListCtrl, (CBitmap*)NULL);
CBitmap bmpCheckBox;
bmpCheckBox.LoadBitmap(IDB_BMP_CHECKBOX);
m_ImageList.Replace(1, bmpCheckBox, (CBitmap*)NULL);
CBitmap bmpComboBox;
bmpComboBox.LoadBitmap(IDB_BMP_COMBOBOX);
m_ImageList.Replace(2, bmpComboBox, (CBitmap*)NULL);
Related
I have 5 images that is to be displayed at the bottom of my screen.
Now what i want is the images to appear one after the other and in a infinite loop type display (i.e After the 5th Image the 1st image should appear). This should go on as long as the user is on this page.
I tried Carousel, but after the 5th image, an auto rewind action takes place and the 1st image is loaded(Horrible).
How do i achieve the same using simple animation ?
Did you tried something like this:
string[] image = { "image1","another","third","oneMore","lastImage"};
int index = 0;
Device.StartTimer(TimeSpan.FromSeconds(5), () =>
{
if(index >= (image.Length - 1))
index = 0;
else
index++;
imgView.FadeTo(0.1, 250, Easing.Linear);
imgView.Source = ImageSource.FromResource(image[index]);
imgView.FadeTo(1, 250, Easing.Linear);
return true;
});
Use a simple Image instead of the CarouselView. Maybe you'll need surround the actions over imgView with a "Device.BeginInvokeOnMainThread". Check it out.
I need to reduce the resolution of the images that I add and show in a QListWidgtet.
Now I use the next code but it does not show all the images because they are being loaded with full resolution
void ImagesWizard::on_pbAddImages_clicked()
{
QFileDialog dialog(this);
dialog.setDirectory(mInitPath);
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter(trUtf8("Images (*.jpg *.png *.tif *.tiff *.bmp);; JPG (*.jpg);; PNG (*.png);; TIF (*.tif *.tiff);; BMP (*.bmp);;"));
QStringList filesToLoad;
if (dialog.exec())
filesToLoad = dialog.selectedFiles();
if (filesToLoad.count()!=0) {
QListWidget *localPathList= new QListWidget();
localPathList->setViewMode(QListWidget::IconMode );
localPathList->setIconSize(QSize(100,100));
localPathList->setResizeMode(QListWidget::Adjust);
localPathList->setSelectionMode(QAbstractItemView::MultiSelection);
for (int var = 0; var < filesToLoad.count(); ++var) {
if (!mImagesList->contains(filesToLoad[var])) {
QFileInfo fileInfo(filesToLoad[var]);
QString filename(fileInfo.fileName());
QListWidgetItem *listItem = new QListWidgetItem(QIcon(filesToLoad[var]),filename);
localPathList->addItem(listItem);
mImagesList->append(filesToLoad[var]);
}
}
pbNext->setFocus();
}
}
Is there any way to resize the resolution in of the QIcon to optimice the time consumed to load the images and to show all the images added?
Now if I load a lot of images the last QListWidgetItems only add the name.
Thanks for your help
Use QImage first to scale the image and construct the icon from the resulting pixmap.
QSize desiredSize;
Qimage orig(filesToLoad[var]);
Qimage scaled = orig.scaled(
desiredSize,
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
QListWidgetItem *listItem = new QListWidgetItem(QIcon(Qpixmap::fromImage(scaled)),filename);
It is very common to store the presized image too on the disk, to avoid the two step conversion process.
As part of a project I am realizing, there are given pdfdocuments which include forms as JPEG Images within A4 pages inside this documents. If have to extract those JPGs out of the PDF. Later on those JPGs are used to build PDF Documents again.
When I simply open up those Documents with any PDFViewer they seem to have no rotation at all, at least it is not visible. So like this icon the have vertical format.
but when I use this sample code to extract the images :
PDDocument doc = PDDocument.load("/path/to/file);
List pages = doc.getDocumentCatalog().getAllPages();
Iterator iter = pages.iterator();
int i = 0;
while (iter.hasNext()) {
PDPage page = (PDPage) iter.next();
System.out.println(page.getRotation());
System.out.println("ROTATION = " + page.getRotation());;
PDResources resources = page.getResources();
Map pageImages = resources.getXObjects();
if (pageImages != null) {
Iterator imageIter = pageImages.keySet().iterator();
while (imageIter.hasNext()) {
String key = (String) imageIter.next();
if(((PDXObjectImage) pageImages.get(key)) instanceof PDXObjectImage){
PDXObjectImage image = (PDXObjectImage) pageImages.get(key);
image.write2file("/path/to/file" + i);
}
i ++;
}
}
}
all extracted JPGs are horizontal format. Further the sysout on the page.rotation tells me that the rotation is set to 270°.
How is that possible? 270 is set, but the PDF is shown vertical (I am no expert on PDF). I even did page.setRotate(0) before extracting the JPGs, but the images still remain horizontally. I read the following Thread telling how to rotate images before drawing them on the pdf. But i need to rotate them before writing them on the filesystem. What is the best way to achieve that?
Unfortunately, I can not attach any of the documents since they are confidential.
I'm trying to write a a multipage (1024 pages to be exact) to file.
for frame=1:num_images
imwrite(output(:,:,frame), 'output.tif', 'tif', 'WriteMode', 'append', 'compression', 'none');
end
I tried this, but writing Int32 to tiff is not supported by imwrite.
I've also tried
tiffObj = Tiff('output.tif', 'w');
tiffObj.setTag('ImageLength', x_size);
tiffObj.setTag('ImageWidth', y_size);
tiffObj.setTag('Photometric', Tiff.Photometric.MinIsBlack);
tiffObj.setTag('BitsPerSample', 32);
tiffObj.setTag('SamplesPerPixel', 1);
tiffObj.setTag('RowsPerStrip', 64);
tiffObj.setTag('SampleFormat', Tiff.SampleFormat.Int);
tiffObj.setTag('TileWidth', 128);
tiffObj.setTag('TileLength', 128);
tiffObj.setTag('Compression', Tiff.Compression.None);
tiffObj.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
tiffObj.setTag('Software', 'MATLAB');
tiffObj.write(output);
tiffObj.close();
The tif I imread() has 1 SamplesPerPixel per frame, but when I try to use the same value I get
SamplesPerPixel is 1, but the number of image planes provided was 1204.
If I set it to 1204 Imagej complains
Unsupported SamplesPerPixel: 1204
This is rather frustrating.
The correct way to write multiple pages to a TIFF file is to call Tiff.writeDirectory after each page (2D image) has been written. I agree, the MATLAB documentation is not very clear there, knowing LibTIFF helps in using the Tiff class. For example:
image = zeros([140,160,16],'uint8'); % this is the image we'll write, should have some actual data in it...
t = Tiff('testing.tif','w');
tagstruct.ImageLength = size(image,1);
tagstruct.ImageWidth = size(image,2);
tagstruct.SampleFormat = 1; % uint
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 8;
tagstruct.SamplesPerPixel = 1;
tagstruct.Compression = Tiff.Compression.Deflate;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
for ii=1:size(image,3)
setTag(t,tagstruct);
write(t,image(:,:,ii));
writeDirectory(t);
end
close(t)
How can I convert single channel IplImage (grayscale), depth=8, into a Bitmap?
The following code runs, but displays the image in 256 color, not grayscale. (Color very different from the original)
btmap = gcnew Bitmap(
cvImg->width ,
cvImg->height ,
cvImg->widthStep ,
System::Drawing::Imaging::PixelFormat::Format8bppIndexed,
(System::IntPtr)cvImg->imageData)
;
I believe my problem lies in the PixelFormat. Ive tried scaling the image to 16bit and setting the pixel format to 16bppGrayscale, but this crashes the form when uploading the image.
The destination is a PicturePox in a C# form.Thanks.
You need to create ColorPalette instance, fill it with grayscale palette and assign to btmap->Palette property.
Edit: Actually, creating ColorPalette class is a bit tricky, it is better to modify color entries directly in btmap->Palette. Set these entries to RGB(0,0,0), RGB(1,1,1) ... RGB(255,255,255). Something like this:
ColorPalette^ palette = btmap->Palette;
array<Color>^ entries = palette->Entries;
for ( int i = 0; i < 256; ++i )
{
entries[i] = Color::FromArgb(i, i, i);
}
int intStride = (AfterHist.width * AfterHist.nChannels + 3) & -4;
Bitmap BMP = new Bitmap(AfterHist.width,
AfterHist.height, intStride,
PixelFormat.Format24bppRgb, AfterHist.imageData);
this way is correct to create a bitmap of a IPLimage.