Solved

problem in setiing  pixel values in the raw bits of the DIB of 24 bit image?

Posted on 2009-04-09
8
218 Views
Last Modified: 2012-05-06
Hi,


  I am working on delphi-7. I have set of pixel values(ie to draw scribbles(colored lines) on image),I want to set the pixels by using the DIB raw bits, My codse is as given below,


           if ((y>0) and (y<Height)  and (x<Width) and (x>0)) then
           begin
             row := (Width *(Height - y)+x)*3;  // (w2*(h2-j)+i)*3;
             (L_PUCHAR(integer(drawbits)+row+2))^  :=   GetRValue(col);
             (L_PUCHAR(integer(drawbits)+row+1))^  :=   GetGValue(col);
             (L_PUCHAR(integer(drawbits)+row))^    :=   GetBValue(col);
           end;  
           StretchDIBits(hdc_draw,0,0,Width,Height,0,0,Width,Height,drawbits,pinfo_curstamp^,DIB_RGB_COLORS,SRCCOPY);
 
           Where
       drawbits is the raw bits obtained from DIB of 24 bit image.



         It is working fine for some 24 bit  images. But with Some 24 bit images it is jumping the scribbles(ie it is not drawing to the same position). Even I am stretching to the 24 RGB bits,I am not getting what is the problem. Please give me solution.
0
Comment
Question by:inampudi1
  • 2
  • 2
  • 2
8 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 24123724
The problem might be related to to the fact that the row width is always a multiple of 4 bytes.  I did not check your calculation, but it must take that into account.  
For instance, if the calculation works for bitmaps that are exactly 320 bits wide but does not work for one that is 321 or 322 bytes wide, then that might be the problem.  Can you check that out and see if it applies?
0
 

Author Comment

by:inampudi1
ID: 24124559
Hi DanRollins,

   Thank you for reply,

   I checked it is right what you are saying. suppose I have image with 317 by 318, Without resizing image how can I Change my DIB drawing algoritham. Please tell me.


0
 
LVL 16

Expert Comment

by:George Tokas
ID: 24126944
Since you are working with Delphi why don't you assign the DIB to a TBitmap and access TBitmap->Canvas->Pixels[x][y] ??

George Tokas.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:inampudi1
ID: 24128842
HI gtokas,

   Assigning DIB to bitmap and then processing pixel by pixel will take extra time, as compared to DIB. Since I am working with 2K resulution images, Pixel by pixel meands it will be slow.

0
 
LVL 16

Expert Comment

by:George Tokas
ID: 24130054
Use scanline. Its faster and there are Delphi examples...

George Tokas.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 24132824
Here is your calculation:
    row := (Width *(Height - y)+x)*3;
The "Height-y" part is to reverse top and bottom. Let's remove that for now...
    row := ((Width * y) +x)*3;
That is saying that each row is Width * 3 bytes long... The address then is y rows (of 3 bytes per pixel times the number of pixels in a row) plus x columns (of three bytes per pixel).
You need to adjust that so that when the Width is not a multiple of 4 pixels, then iou take that into consideration
    nScanLineWide = ((Width+3) /4) * 4; // round up next multiple of 4
    row := ((nScanLineWide* y) +x)*3;
(and adding back the top=bottom adjustment:
    row := ((nScanLineWide * (Height - y) ) +x)*3; // BTW, 'row' is a bad name for this variable
Note: I did not actually test this, as I have no experience with Delphi. But the basic princlple is commonly used on C++ and Assembly Language coding, so I assume it applies here.  Also, I'm assuming that variables and intermediate values are integer data type so that (z+3)/4 yields an integer.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 132
Delphi Form ownership 4 88
Delphi and Access based Enumeration 9 63
Twebbrowser in Fire monkey android scrolling to bottom 1 30
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question