Visual C++ :: Program To Resize Image?
Feb 19, 2013
I am currently working on problem set 4 for Harvard's online CS50 course. I am working on a program that resizes a bmp image by a factor of N. N in entered along with an in-file and out-file in a command line argument. The program needs to calculate the header file for the out-file and write it to the out-file. It then needs to actually resize the image and, again, write to the out-file.
The first question I have relates to the header file, here is my code for calculating the header file:
bi2.biHeight = bi.biHeight *n;
bi2.biWidth = bi.biWidth *n;
int padding = (4 -(bi.biWidth * sizeof(RGBTRIPLE))%4)%4;
bi2.biSizeImage = (bi2.biWidth * sizeof(RGBTRIPLE) + padding) * abs(bi2.biHeight);
bf2.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bi2.biSizeImage;
And here is my code for writing the new header file (bi2 and bf2) to the out-file:
fwrite(&bf2, sizeof(BITMAPFILEHEADER), 1, outptr);
fwrite(&bi2, sizeof(BITMAPINFOHEADER), 1, outptr);
At this point I need to actually resize the image. As far as I can tell there are 2 ways to go about this you either have to use an array to store each line you want to print repeatedly (and then you can just write it repeatedly) OR you have to move the pointer back in the input stream and repeat the read/resize/write process each time you need to print the row.
It is this that I am stuck on, first of all, I am not sure what system would be better for resizing the image, although I am leaning towards using an array, and regardless, I don't even know where to begin when in implementing either.
So what I am asking for is, first of all, just a "double check" to make sure my header code makes sense. And second of all, a push in the right direction for actually resizing the image. Here is my complete code:
/****************************************************************************
* resize.c
*
* Resizes a BMP piece by piece, just because.
***************************************************************************/
#include
#include
#include "bmp.h"
int main(int argc, char* argv[]) {
// ensure proper usage
if (argc != 4) {
printf("Usage: copy N infile outfile
[Code]....
View 7 Replies
ADVERTISEMENT
Aug 22, 2014
I am trying to re-size a bitmap image for a class.They gave us two options to use to do the program with: an array or move the file position indicator. I want to use the file option. All the bitmap header info is checking out. The file after being re-sized should be 822 bytes but it is 1.6 KiB and the image is distorted.
Code:
#include <stdint.h>
/**
* Common Data Types
*
* The data types in this section are essentially aliases for C/C++
* primitive data types.
[Code]...
View 2 Replies
View Related
Nov 22, 2014
I have a bit map which I wants to re-size according to new point. But on Paint Event Method getting error not Implemented.
CODE Under Paint Event Method
private void pictureBox3_Paint(object sender, PaintEventArgs e) {
Point[] destinationPoints = {new Point(200, 20),new Point(110, 100),new Point(250, 30), new Point(250, 30) };
Image image = new Bitmap("D:\APP\Resources\MyPic.Png");
// Draw the image mapped to the parallelogram.
e.Graphics.DrawImage(image, destinationPoints);
}
View 5 Replies
View Related
Oct 27, 2014
Is there any way to allow user to resize a CDialog only in one direction ? I mean, by width, but not by height ? How ? I noticed that overriding WM_SIZE, I can do nothing about this issue ...
View 2 Replies
View Related
Jul 29, 2014
I am writing a program to display values from a data file as an image. But I can only get a blue screen. Here is a small program resembling my code. what I have missed? I only changed OnDraw function.
Code:
void CColorDisplayView::OnDraw(CDC* pDC) {
CColorDisplayDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rect;
[code].....
View 10 Replies
View Related
May 17, 2014
any easy way to resize property sheet/page dialogs automatically or semi automatically?. have tried too many stuff, but none were fruitful.
View 5 Replies
View Related
Jul 3, 2014
Im trying to compare the image of a button to another image in Visual Studio like so...
//variables
Image active = Image.FromFile("C:\Users\Ethan\Desktop\StarWars Status\active.png");
Image stunned = Image.FromFile("C:\Users\Ethan\Desktop\StarWars Status\stunned.png");
[Code]...
btnStatusPlr1.Image SHOULD come back as True.Then I realized it might not be the same as setting the buttons image in the properties (Which is what i did to get the original image (the one being compared to))
I do have a feeling ive done something wrong here (Yes im a noob /> )
Variable active, is the same image as the buttons default (Well should be)
View 1 Replies
View Related
Jan 27, 2013
how to create, initialize, and maintain a memory device context that works as a local buffer for images? The idea is to maintain some large images in local DCs and bitmaps, and only bitblt them to screen in OnDraw().
What I did so far was was to define CDC and CBitmap objects as members of my View class, and then tried to initialize them with the sequence that begins at "// Initialize buffer". I placed that sequence in either OnInitialUpdate, or PreCreateWindow, or OnPrepareDC, or the view constructor, to no avail. The code always crashes in OnDraw, and I've noticed that the m_hDC member of myDevice is zero at that point.
Obviously, the initialization is wrong and MFC does (too many) things in the background which I'm not aware of.... My question was where can I read about that?
Code:
class CMyView : public CScrollView {
// ...
CDC myDevice;
CBitmap bmp;
CBitmap *oldbmp;
[Code] .....
View 5 Replies
View Related
Sep 23, 2013
I have the raw image data and now want to convert it to PNG image. How can i do that? The raw image data is stored in a unsigned char *.
I know how to convert it to Bitmap, but how to convert it to PNG.
View 2 Replies
View Related
Mar 20, 2014
Which command should i use for displaying a jpeg image in Visual Studio 2008 (VC++)?In the past i used LoadImage function for displaying Bitmaps.
View 14 Replies
View Related
Jul 30, 2014
tell me the EASIEST way to create a button with an image on it.
I am not interested in using the owner draw property with CBitmapButton and then have to create a whole lot of bitmaps for all the different button states.
There must be a way to simply create an ordinary button which displays an image rather than or as well as a caption....?
View 3 Replies
View Related
Apr 26, 2013
I have a jpg file. I have extracted the width and the length of the image. I have done that with some codes and markers. Now I need the image data starts as from that place i would like read the data and print the pixel value. I would like to display the pixels later.
View 2 Replies
View Related
Dec 26, 2013
I am working on a Windows application using Visual Studio 2012. One of the screens have a text entry field for the user. Instead of using a standard text field control, am placing a image which looks exactly like a text field. Now what i want to do is, capture the key stroke and update this image with the characters entered by user.
The initial image shown to the user is "Blank_Text_Entry.png" and this is added to the resource as IDB_BLANK_TEXT_ENTRY.
This is a rectangular white image with dimensions 153 x 27, with a size of 250 bytes.
My goal is to be able to update this image dynamically based on key strokes by user and display it.
View 5 Replies
View Related
Aug 2, 2013
I have created an application that has bunch of buttons on top and i want to change the image when I click on the button. But unfortunately I can't get it to work.
Here is the code:
if (serialPort1.IsOpen) {
tsbCommPortOpenClose.ToolTipText = "Open serial port";
closeCommPortToolStripMenuItem.Text = "Open serial port";
tsbCommPortOpenClose.Image = Image.FromFile("Red.bmp");
serialPort1.Close();
[Code] ....
The second one which changes the image to "image2" works fine. Here is the definition of image2:
namespace Regress;
...
private Bitmap image2;
System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
StreammyStream = myAssembly.GetManifestResourceStream("Regress.Sharing.gif");
image2 = new Bitmap(myStream);
When I do the same with the other image that I want to use, it won't work! I opened the project properties and added the image into the resources too, and it still doesn't work. It fails and says the file was not there. I've put a copy of the file in the root directory and one in "Resources" folder but it still doesn't work.
View 3 Replies
View Related
Nov 25, 2012
Used some online code example to put a little project to display raw image. The display does not seem to work.For some purposes, I like this to work with a dialog based MFC project.XDVView is derived from CScrollView.
See OnInitDialog() and OnDraw(CDC* pDC).8bit 768x756
View 14 Replies
View Related
Mar 12, 2013
I m loading a png image by using the ATLImage library.
CImage Image;
Image.Load (L"D:ImagesPNG_ImagesImage7.png");
how to retrieve the byte array value of this png image. I tried retrieving it as
byte *png = reinterpret_cast<BYTE *>(Image.GetBits());
but when i access the data , der is a loss of data while converting it in the above manner.
I found a snippet in net for decoding the raw data . but der is a line is the code which is unknown to me. The code is as follows :
CImage atlImage;
HMODULE hMod = GetModuleHandle(NULL);
atlImage.Load(bstr);
void* pPixel = atlImage.GetBits();
intpitch = atlImage.GetPitch();
intdepth = atlImage.GetBPP();
[Code] ....
How do I get the byte * value form the png image loaded?
View 3 Replies
View Related
Nov 20, 2014
I have an *.lct file. I like to read *.lct file and save an bmp image.
I can not read this file using usual file read.
Code:
void CLCTtoBMPDlg::OnBnClickedReadlctfile() {
CFileException CFileEx;
CStdioFile ReadFile;
CString OpenlctfilePath;
TCHAR szFilters[]= _T("LCT Files (*.lct)");
CFileDialog fileDlg(TRUE, _T("bmp"), _T("*.lct"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
[Code]...
Find the attachment. change the file extension *.lct instead of *.txt. I like to read ASCII Data into Hex, Example : Data "A" as "41" (Refer the jpeg image). How is possible?
View 4 Replies
View Related
Feb 8, 2013
I like to Draw an Image Using two dimensional byte array[512][256].
I used SetPixelV method to plot the image.
But Its very slow & hidden some buttons(Controls) at run time in the same dialog.
For reference i send some code,
Code:
for(row = 0; row <512; row ++)
{
for(col = 0; col < 256; col++)
{
Data[row][col] = y;
SetPixelV(d, 10+row, 10+col, RGB(Data[row][col],Data[row][col],Data[row][col]));
}
}
View 14 Replies
View Related
Mar 11, 2014
The documentation states that "An image list is a collection of same-sized images" [URL].....
But how do I retrieve that size? I have a pointer to an empty image list. The size was set during creation, but that's out of my control.
View 8 Replies
View Related
Jan 21, 2014
I have a VisualC++ program to display image data to the screen. The data is a 24-bit, RGB bitmap that is properly shown using BitBlt().
I have a CopyWindow() function that puts the BITMAPINFO structure and RGB image data on the clipboard as a DIB with the SetClipboardData(CF_DIB,...) call.
My problem happens when I try to paste the image into MS Powerpoint (Office 2010). I've tried Paste and all the options in Paste Special but the image will not appear.
If I open Paint and do a Paste, the image appears properly in that application. Then I can do a Copy from there and am able to Paste that into Powerpoint.
How is Paint able to accept the DIB? And what is different about how Paste puts that bitmap onto the Clipboard so that Powerpoint can see it?
View 4 Replies
View Related
Jan 28, 2013
I want to create a program using c++ which will accept text from the user and then adds it onto a image of a form in specific locations (if that makes sense?)
and what libraries will be required?
View 1 Replies
View Related
Apr 2, 2013
I am trying to write a program that creates a hybrid image I've hit a roadblock early on my code throws up an unhandled exception I cant find where it goes wrong I need a fresh perspective on this. Here is my code so far
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
using namespace cv;
Point P11, P12;
Point P21, P22;
[Code] .....
View 5 Replies
View Related
Jul 31, 2014
An ImageList_Create() function (see here) takes 2 parameters: cx and cy which are the width and height of each image.
Everything is good if I know in advance what size my images will have. But what if I don't?
Let's say I select 32x32 and my images are sized as 16x16. What will happen with the image list? Or my images are 48x48 and the image list should grow to accomodate the extra space. Since on Windows image list is just one big bitmap, will the height of the image list shrink/grow to 16/48 or not? Is there a way to test such behavior?
The problem I'm having is to check whether the actual images will be truncated when they are bigger that the image list initial size or not or whether I will see some extra space if the images are smaller.
The closest way I see is this function, but I am not sure its the right one to apply to the image list itself and not to the image inside the list.
How to test this properly and reliably on Windows XP+?
View 3 Replies
View Related
Mar 11, 2014
My requirement is,
Read *.bmp image and displaying bitmap image with scrollbar in a MFC dialog application.
I was done using this
I was read the *.bmp image as a pixel data and stored by 2D Array,
Now i want to Display this 2D array as bitmap image with scrollbar separately in the same dialog. How can i display bitmap with scrollbar using 2D array?
View 10 Replies
View Related
Jan 25, 2015
How to insert and read images to/from database (sql server) using MFC ?
View 5 Replies
View Related
Mar 14, 2013
Need a free image library that can handle png xresolution and yresolution. I need it to be compatible with visual studio 6.0
View 1 Replies
View Related